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

Source: Internet
Author: User
Tags set set

In the project, you will encounter a one-to-many entity relationship mapping, and you should also isolate the associated entity properties, and use the join statement in HQL to associate two entity objects with the following code:

1 New Customerrequirement (c.pname,c.salesman,c.pdate) from customerrequirement C inner joins c.requirementdeatils r on C = C.req Uirementdeatils.customerrequirement

Run the discovery report with the following error:

Org.hibernate.QueryException illegal attempt to dereference collection

This is because in the HQL statement above, Customerrequirement's associated entity requirementdeatils is a set set, not an entity. In previous versions of Hibernate3.2.2, Hibernate automatically used an implicit inner join for the associated entity, meaning that using the HQL statement above was 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 HQL statement. If requirementdeatils is a single associated entity or is a normal attribute, Hibernate automatically uses the implicit inner join. But if requirementdeatils is a collection, then there will be org.hibernate.QueryException illegal attempt to dereference Collection exception, for the solution is either to return to the hibernate3.2.2 version before, or use the following form of the HQL statement:

New  Customerrequirement (c.pname,c.salesman,c.pdate) from customerrequirement C INNER join fetch c.requirementdeatils r on C = C.requirementdeatils.customerrequirement

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.