Hi everybody !
I'm currently having a problem with the construction of a criteria.
I have an Object called X which have a list of Y element. Y is a composite-element with reference to Z element.
I have to construct a query which search any X objects which have at least 1 Z element in common with the list of Z elements that I pass in parameter.
The mapping is the following :
Code:
<class name="X" table="x">
...
<list name="elements" table="elements" cascade="all">
<key column="x"/>
<list-index column="index"/>
<composite-element class="Y">
<property name="date" type="java.util.Date">
<column name="date" sql-type="date"/>
</property>
<many-to-one class="Z">
<column name="z"/>
</many-to-one>
</composite-element>
</list>
</class>
And the query is the following :
Code:
criteria = session.createCriteria(X.class);
criterion = null;
for (Z zTemp : listParameters) {
if (criterion == null) criterion = Restrictions.eq("z", zTemp);
else criterion = Restrictions.or(criterion, Restrictions.eq("z", zTemp));
}
criteria.createCriteria("elements").add(criterion);
return criteria.list();
If I execute this query, I have the following error :
Code:
org.hibernate.MappingException: collection was not an association: X.elements
at org.hibernate.type.CollectionType.getAssociatedEntityName(CollectionType.java:367)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathEntityName(CriteriaQueryTranslator.java:191)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:175)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:81)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:69)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1287)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:299)
Any idea ?