hibernate-list

Hibernate多表关联查询类:

    1. sql查询两个或两个以上的字段,默认情况下,list中封装的是Object[],长度与所查询的字段数一致。这种方式获取的数据只能通过index下标获取。  

super.getSession().createNativeQuery(dataSql).getResultList();

    2. hql 查询,在hql中使用select new 包名.类名(属性1,属性2……)将结果放入到非实体的DTO中,这种有点固化。

select new  com.***.***.**DTO(属性1,属性2,属性3) from  *****

   3. sql查询,使用 setResultTransformer,将结果进行转化,转化成Map或者Bean对象。但5.2版本被 @Deprecated了,6版本可能会加入labada表达式。

setResultTransformer(Transformers.aliasToBean(UserDTO.class)).getResultList()

 官方回复是:

For the moment, there is no replacement.

In 6.0, the ResultTransformer will be replaced by a @FunctionalInterface, but the underlying mechanism of transforming the Object[] property values will probably be the same.

Therefore, you can use it as-is and, only if you upgrade to 6.0, you will have to think about replacing it with the new variant.

 4. hql查询或sql查询,如果返回结果为实体类(@Entity修饰与表有关联),则使用  

createNativeQuery(dataSql,  USERDO.class)
  或者
createNativeQuery(dataSql).addEntity(USERDO.class)

 

 

 

 

 

 

转载于:https://www.cnblogs.com/DennyZhao/p/7145342.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值