Hi I use JBPM, where class VariableInstance has an association to any business object mapped as any type (association is mapped in two columns to db one column is class name, second is id of object). Is it possible to write a query against VariableInstances which reference to business object that meets some criteria? I can write a query using plain sql, because I always know what type by business object (table) it is and what its id is.
I tried to do it this way
//criteria used to select business object
DetachedCriteria dcVariableObject = ...
DetachedCriteria dcVariableInstance = DetachedCriteria.forClass(HibernateLongInstance.class)
.add(Property.forName("value").in(dcVariableObject));
Does not work!
org.hibernate.QueryException: property does not map to a single column: value
Second try
//criteria used to select business object with projection to id
DetachedCriteria dcVariableObject = ... .setProjection(Projections.id());
//ids of business objects meeting criteria
List<Long> dc = dcVariableObject.getExecutableCriteria(session).list();
DetachedCriteria dcVariableInstance = DetachedCriteria.forClass(HibernateLongInstance.class)
.add(Restrictions.sqlRestriction("LONGVALUE_ in ? ", dc, Hibernate.LONG));
Does not work neither! ClassCastException, because there is no type collection/array of long.
Thanks for any help
Fero
|