最后一种映射类型,就是实体与标量值的组合
@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映射机制来保存用本地查询得到的结果集,具体采取哪种要看具体的情况,要继续了解这方面的知识。
本文介绍了一种使用@SqlResultSetMapping注解实现的混合映射机制,该机制能将查询结果的一部分映射到实体对象,另一部分则作为标量值返回。通过示例展示了如何定义这种映射,并成功运行测试程序验证其正确性。
6125

被折叠的 条评论
为什么被折叠?



