zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    保存会话数据——cookie学习
    HttpServletRequest学习
    HttpServletResponse 学习
    Servlet学习
    Http协议简单学习笔记
    利用tomcat配置网站
    PHPCMS-V9 获取一级栏目、二级栏目、三级栏目
    PHP判断当前访问的是 微信、iphone、android 浏览器
    二维数组根据某个字段排序
    动物界的再生一个故事
  • 原文地址:https://www.cnblogs.com/DennyZhao/p/7145342.html
Copyright © 2011-2022 走看看