I am doing a criteria projection query which joins two tables. this is a little weird, but I also want the object of the original criteria. The only Projection I can see to use is a field of the original object, but not the object itself. I need a "this" or something keyword or new projection type. I see I can get the id of the object, but I would like the object itself.
Thanks,
Chris
ps. below I try to get the alias of the object, which says obviously it cant find the field...
Hibernate version:
3.1
Code between sessionFactory.openSession() and session.close():
Code:
final ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.property("courtCase__"));
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.toType(AbstractEntityPersister.java:1265)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getType(CriteriaQueryTranslator.java:476)
at org.hibernate.criterion.PropertyProjection.getTypes(PropertyProjection.java:36)
at org.hibernate.criterion.ProjectionList.getTypes(ProjectionList.java:38)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:317)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:69)
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:104)
at gov.me.bds.osa.drugcourt.util.HibernateHelper.callbackHibernateSession(HibernateHelper.java:1219)
at gov.me.bds.osa.drugcourt.util.HibernateHelper.callbackHibernateSession(HibernateHelper.java:1183)
Name and version of the database you are using:
Oracle