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.
By looking at the data, we found that in the HQL statement above, brand's associated entity styles is a set set, not a style 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 styles is a single associated entity or is a normal attribute, Hibernate automatically uses the implicit inner join. But if Styles 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 the hibernate3.2.2 version or use the following form of the HQL statement:
From Brand as B inner join fetch b.styles as s where s.styleid=?