When I was working on a project today, there were two entities: style and brand. The relationship between the two was many-to-many. The function was to select a style and display all the brands of the style. HqlThe statement is as follows:
1 FromBrandAsBWhereB. Styles. styleid=?
This exception occurs during running: org. hibernate. queryexception: illegal attempt to dereference collection.
the preceding hql in a statement, Brand's associated entity styles is a set, instead of a style object. In hibernate3.2.2 previous versions, hibernate automatically uses the implicit Inner join , that is, the preceding hql the statement is no problem.
HoweverHibernate3.2.2Versions later,HibernateThis policy has been changed. It uses the following policy to associate objects.
For Hql Statement. If Styles Is a single correlated entity or a common attribute Hibernate It automatically uses the implicit Inner join . However, if Styles Is a collection, so sorry, The system will appear Org. hibernate. queryexception: illegal attempt to dereference collection Exception.
For the solution, either you return the hibernate3.2.2 Before the version, either Hql Statement:
1 FromBrandAsBInner Join FetchB. StylesAsSWhereS. styleid=?