今天做项目的时候,有两个实体:款式、品牌两者关系是多对多的关联关系,实现的功能是:通过选择款式,显示出该款式的所有品牌。HQL语句如下:

运行时出现这个异常错误:org.hibernate.QueryException: illegal attempt to dereference collection 。

通过查资料发现,在上面的HQL语句中,Brand的关联实体styles是一个Set集合,而不是一个Style实体。在 Hibernate3.2.2以前的版本,Hibernate会对关联实体自动使用隐式的inner join,也就是说使用上面的HQL语句是毫无问题的。

但是在Hibernate3.2.2版本以后,Hibernate改变了这种策略。它使用如下策略来关联实体。

同样对于上面的HQL语句。如果styles是一个单个的关联实体或者是一个普通的属性,那么hibernate就会自动使用隐式的inner join。但是如果styles 是一个集合,那么对不起,统将会出现 org.hibernate.QueryException: illegal attempt to dereference collection异常。 对于解决方案就是,要么你退回hibernate3.2.2版本以前,要么使用如下形式的HQL语句:

解决org.hibernate.QueryException illegal attempt to dereference collection 异常错误的更多相关文章

  1. 【Hibernate】Illegal attempt to associate a collection with two open sessions

    今天在用Hibernate对对象进行修改操作的时候报了这个错. 之前一直没什么错误,但是今天修改了一下表结构,增加了一个OneToMany的映射. 所以在我获取对象,重新set一个变量之后就报了这个错 ...

  2. 解决xorm逆向mssql报datetime2不兼容的异常错误

    xorm作为golang开发者的一大利器,深受大家的喜爱,可是最近在逆向mssql的时候,报了这么一个错误: 最后找了半天发现xorm没有预置DateTime2类型,经过几番折腾,在xorm源码的en ...

  3. 常见Hibernate报错处理:出现“org.hibernate.QueryException: could not resolve property”和 is not mapped和could not locate named parameter错误的解决

    正确写法: @Override @SuppressWarnings("unchecked") public List<Device> queryOSDevice(Str ...

  4. weblogic 下异常 org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken

    项目之前在 Tomcat 环境下一直都正常运行,今天应客户要求需要迁移到 webLogic 10.3.6 下, 部署后竟然抛出了 org.hibernate.QueryException: Class ...

  5. nested exception is org.hibernate.QueryException: could not resolve property

    SSH框架出现了下面的错误: nested exception is org.hibernate.QueryException: could not resolve property 检查了hbm.x ...

  6. org.hibernate.QueryException: could not resolve property

    org.hibernate.QueryException: could not resolve property HibernateSQLXML  org.hibernate.QueryExcepti ...

  7. atitit. 解决org.hibernate.SessionException Session is closed

    atitit. 解决org.hibernate.SessionException Session is closed   #--现象:: org.hibernate.SessionException ...

  8. org.hibernate.QueryException: could not resolve property: address of:

    Hibernate: select count(*) as y0_ from test.course this_ org.hibernate.QueryException: could not res ...

  9. 同时操作两个数据库:报错Illegal attempt to associate a collection with two open sessions

    今天我在一个操作两个数据库的SSH里 同时插入1条数据 报错 Illegal attempt to associate a collection with two open sessions 在这里有 ...

随机推荐

  1. 转载hibernate 的3种 状态 。。

    转自  http://huangtut.iteye.com/blog/261520  对我有帮助,所以收藏了 Hibernate三种状态的区分,以及save,update,saveOrUpdate,m ...

  2. 2018.10.14 loj#6011. 「网络流 24 题」运输问题(费用流)

    传送门 费用流入门题. 直接按照题意模拟. 把货物的数量当做容量建边. 然后跑一次最小费用流和最大费用流就行了. 代码: #include<bits/stdc++.h> #define N ...

  3. 2018.08.01 BZOJ4552: [Tjoi2016&Heoi2016]排序(二分+线段树)

    传送门 线段树简单题. 二分答案+线段树排序. 实际上就是二分答案mid" role="presentation" style="position: relat ...

  4. Cygwin工具的简单使用

    简介 从使用角度来看:Cygwin就是一个windows软件,该软件就是在windows上仿真linux操作系统.简言之,cygwin是一个在windows平台上运行的 linux模拟环境,使用一个D ...

  5. git将本地仓库强制替换掉远程仓库

    $ git remote add origin <url> $ git push --force --set-upstream origin master

  6. Caused by: Unable to load configuration. - action - file:/C:/apache-tomcat-7.0.70/webapps/Structs/WEB-INF/classes/struts.xml:7:72 at com.opensymphony.xwork2.config.ConfigurationManager.getConfigurati

    Unable to load configuration. - action - file:/C:/apache-tomcat-7.0.70/webapps/Structs/WEB-INF/class ...

  7. day07(Set接口,HashSet类,hashcoad(),Collections工具类,Map集合)

    Set接口 set接口的实现类特点 1.无序(取出来的顺序和存进去的数据的顺序不一致) 2.唯一(数据不能存相同的) 底层是用Map集合写的 HashSet类  实现了  set接口       唯一 ...

  8. [redis] redis 如何删除匹配模式的多个key值

    redis-cli keys "user:*" | grep "user:[0-9]\+$" | xargs redis-cli DEL redis-cli k ...

  9. Delphi Dll 动态调用例子(3)-仔细看一下

    http://blog.163.com/bxf_0011/blog/static/35420330200952075114318/ Delphi 动态链接库的动态和静态调用 为了让人能快速的理解 静态 ...

  10. JavaScript從剪切板中獲取圖片並在光標處插入

    edit_content_text.addEventListener('paste', function (ev) {    var clipboardData, items, item;    co ...