Solve the Exception error of org. hibernate. queryexception illegal attempt to dereference collection.

Source: Internet
Author: User

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=?

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.