您的位置:首页 > 产品设计 > UI/UE

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

2013-12-08 10:32 525 查看
项目中想级联查询表中的某些字段发生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类中建立相应类型的构造方法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐