最后一种映射类型,就是实体与标量值的组合
@SqlResultSetMapping
(
name="ReturnOrderListWithPartEntityPartScalarType",
entities=
{
@EntityResult
(
entityClass=entity.Order.class,
fields=
{
@FieldResult(name="id",column="order_id"),
@FieldResult(name="date",column="order_creation_date"),
@FieldResult(name="desc",column="order_description"),
@FieldResult(name="sum",column="order_sum_total")
}
),
@EntityResult
(
entityClass=entity.Customer.class,
discriminatorColumn="customer_type",
fields=
{
@FieldResult(name="id",column="customer_id"),
@FieldResult(name="ctype",column="customer_type")
}
)
},
columns=
{
@ColumnResult(name="customer_name")
}
)
我们将结果集中与订单有关的保存进Order Entity,把与Customer有关的,将id和customer type 保存进Customer Entity,把customer name保存进标量。
经过运行测试程序,得到
*****ReturnOrderListWithPartEntityPartScalarType*****
entity.Order@48edb5 entity.GoldenCustomer@1ee2c2c John Smith
entity.Order@1402d5a entity.GoldenCustomer@1ee2c2c John Smith
entity.Order@1e13e07 entity.GoldenCustomer@1ee2c2c John Smith
综上所述,我们可以采取多种resultset映射机制来保存用本地查询得到的结果集,具体采取哪种要看具体的情况,要继续了解这方面的知识。