illegal attempt to dereference collection
2016-05-18 14:18
267 查看
illegal attempt to dereference collection
首先说一句:是版本的问题!在多对多或者多对一,从一中查找多中查询某些语句时容易出现
我写的hql为:
from Dept as d where d.emp.name='Tom';
运行时出现异常:org.hibernate.QueryException: illegal attempt to dereference collection
是因为:在上面的HQL语句中,Dept 的关联实体emp是一个集合,而不直接是一个Emp实体。
在Hibernate3.2.2以前的版本,Hibernate会对关联实体自动使用隐式的inner join,
也就是说如下SQL语句不会有任何问题 :from Dept as d where d.emp.name='Tom';
从Hibernate3.2.3以后,Hibernate改变了这种隐式的inner join的策略
如果emp是也一个集合,那么对不起!系统将会出现 org.hibernate.QueryException: illegal attempt to dereference collection异常。
据Hibernate官方说法:
这样可以让这使得隐含关联更具确定性(原文:This makes implicit joins more deterministic )。
推荐这样写:
from
Dept as d inner join fetch d.emp as s where s.name='Tom';
相关文章推荐
- 前端学习
- 剑指offer-第十题方法总结
- 你是什么样的前端coder?
- HTML img.src图片不存在,则显示另一张图片
- CSS3实现半像素边框
- jquery使用类似于java的集合
- [转载]React.js 2016 最佳实践
- React和Redux的连接react-redux
- 自定义标题时you can not combine custom title with other title features
- [repost]State of the Art JavaScript in 2016
- webpack配置浅析
- 前端常用知识链接地址
- 自动提取HTML中的JS进行合并与压缩
- js判断undefined类型
- ssh框架与json的整合,没导入相应jar包报的错误提示
- html常用标签
- css优先级
- NodeJs处理post请求
- Qt自定义样式/无边框窗口/子窗口模态/非模态问题
- NodeJs的阻塞和非阻塞