JPA本地查询(Native Query)的总结3

最后一种映射类型,就是实体与标量值的组合

 

    @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有关的,将idcustomer 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映射机制来保存用本地查询得到的结果集,具体采取哪种要看具体的情况,要继续了解这方面的知识。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值