hibernate异常Hibernate异常:query specified join fetching, but the owner of the fetched association was n

来源:互联网 发布:wow数据库7.2 编辑:程序博客网 时间:2024/05/22 07:07
项目中想级联查询表中的某些字段发生Hibernate异常:query specified join fetching, but the owner of the fetched association was not present in the select list异常,查了很多资料没有解决最后还是自己乱碰解决了。现记录如下:
      new StringBuffer()        .append("select new com.jhzy.model.News(n.id, n.title, n.source, n.flag,  n.addTime, nt) from News n left join  n.newsType nt left join  n.user u  where ")        .append("(nt.name ")        .append(" like '%")        .append(paramValue)        .append("%' or n.source like '%")        .append(paramValue)        .append("%' or ")        .append(" n.title")        .append(" like '%")        .append(paramValue)        .append("%') order by n.flag desc, nt.sequence asc, n.addTime  desc")
用new 生成查询对象的时候就不用fetch关键字,但是得在model类中建立相应类型的构造方法
原创粉丝点击