Fix org.hibernate.QueryException illegal attempt to dereference collection exception error

Source: Internet
Author: User
Tags set set

Today, when doing the project, there are two entities: style, brand relationship is many-to-many relationships, the realization of the function is: through the selection of styles, showing the style of all brands. The HQL statement is as follows:

From Brand as b where b.styles.styleid=?

This exception error occurred at runtime: Org.hibernate.QueryException:illegal attempt to dereference collection.

           through data found in the above statement, Brand's associated entity styles is a set set, not a style entity. In   previous version, hibernateinner  Join The statement is no problem.

However , after the Hibernate3.2.2 version,Hibernate changed this strategy. It uses the following policy to correlate entities.

Also for the above statement. If is a single associative entity or a common attribute, then the Span style= "Font-family:times New Roman;" >hibernateinner join< Span style= "font-family: the song Body;" > But if is a collection, then I'm sorry, the system will appear  org.hibernate.queryexception: illegal attempt  to dereference collection exception. For the solution, either you return Hibernate3.2.2 statement:

 from  as Inner Join Fetch  as where S.styleid=?  

Fix org.hibernate.QueryException illegal attempt to dereference collection exception error

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.