First say: Is the version of the problem!
In many-to-many or many-to-one, it is easy to find some statements from the one-to-many query
I wrote the HQL for:
From Department as D where d.employees.name= ' Tom ';
An exception occurred at runtime: Org.hibernate.QueryException:illegal attempt to dereference collection
Because: in the HQL statement above, department's associated entity employees is a collection, not directly an employee entity.
In previous versions of Hibernate3.2.2, Hibernate automatically used the implicit inner join for the associated entity,
In other words, the following SQL statement will not have any problem: from Department as D where d.employees.name= ' Tom ';
Since Hibernate3.2.3, hibernate has changed the strategy of this implicit inner join.
For the following statement:
From Department as D where d.employees.name= ' Tom ';
If employees is an ordinary component property, or a single associated entity, Hibernate automatically generates an implicit inner join
If MyEvents is also a collection, then I'm sorry! The system will appear org.hibernate.QueryException:illegal attempt to dereference collection exception.
According to hibernate official saying:
This allows the implicit association to be more deterministic (original: This makes implicit joins more deterministic).
It is recommended to write:
From Department as D INNER join fetch d.employees e where e.name= ' Tom ';
From: http://lishibo613.blog.163.com/blog/static/116100391201010114314573/