Hi all,
I am trying to execute a query, using the criteria API, on a class that has an association mapped using the <any> mapping.
Here is the relevant part of the hbm.xml:
Code:
<class name="Site" table="SIS_NN_SITE_T">
...
<any name="parent" id-type="string" meta-type="integer">
<meta-value class="SiteGroup" value="1" />
<meta-value class="Domain" value="2" />
<column name="SITE_PARENT_TYPE" />
<column name="SITE_PARENT_ID" />
</any>
...
Here is the Java code for the query:
Code:
criteria.createAlias("parent", "parentSite");
criteria.add(Expression.like("parentSite.siteInfo.name", "%" + siteName + "%").ignoreCase());
I get this exception:
Code:
java.lang.UnsupportedOperationException: any types do not have a unique referenced persister
at org.hibernate.type.AnyType.getAssociatedEntityName(AnyType.java:322)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathEntityName(CriteriaQueryTranslator.java:207)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:191)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:81)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:58)
Now, I think I understand the exception: Hibernate can't know from which table to query (in fact, it should query both "siteGroups" and "domains" tables).
This is understandable. My question, therefore, is how can I perform such a query? Is there any way to do a query on ALL tables associated via the <any> element?
Thanks,
Naaman