I am trying to do a criteria join query, and I would like an "in" clause which works on the original object. The only way I can get in to work is by fields. Can someone please help? You see below where I try to do an "in" by the alias of the original object, you can see the stacktrace that this does not work.
Thanks,
Chris
Hibernate version:
3.1
Code between sessionFactory.openSession() and session.close():
Code:
CourtCase courtCase = new CourtCaseDAO().findByPK(new Integer(86));
CourtCase courtCase2 = new CourtCaseDAO().findByPK(new Integer(8031));
final List someList = new ArrayList();
someList.add(courtCase);
someList.add(courtCase2);
final ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.property("sub__.gender"));
projectionList.add(Projections.property("sub__.race"));
projectionList.add(Projections.property("sub__.dob"));
projectionList.add(Projections.property("sub__.clientId"));
List theResults = (List)HibernateHelper.callbackHibernateSessionUnchecked(new HibernateHandler() {
public Object callback(Session hibernateSession) throws Exception {
Criteria criteria = hibernateSession.createCriteria(CourtCase.class, "courtCase__");
criteria.createCriteria("client", "sub__");
criteria.setProjection(projectionList);
criteria.add(Restrictions.in("courtCase__", someList));
return criteria.list();
}
});
Full stack trace of any exception that occurs:testInitObjectFieldOneToMany(gov.me.bds.osa.drugcourt.util.HibernateHelperTest)org.hibernate.QueryException: could not resolve property: courtCase__ of: gov.me.bds.osa.drugcourt.model.CourtCase
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1282)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1257)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:433)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:393)
at org.hibernate.criterion.InExpression.toSqlString(InExpression.java:35)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:333)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:71)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1514)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at gov.me.bds.osa.drugcourt.util.HibernateHelperTest$1.callback(HibernateHelperTest.java:103)
at gov.me.bds.osa.drugcourt.util.HibernateHelper.callbackHibernateSession(HibernateHelper.java:1219)
at gov.me.bds.osa.drugcourt.util.HibernateHelper.callbackHibernateSession(HibernateHelper.java:1183)
at gov.me.bds.osa.drugcourt.util.HibernateHelper.callbackHibernateSessionUnchecked(HibernateHelper.java:1163)
at gov.me.bds.osa.drugcourt.util.HibernateHelperTest.testInitObjectFieldOneToMany(HibernateHelperTest.java:95)
Name and version of the database you are using:Oracle
[/code]