Hibernate version: 3.2.6
Full stack trace of any exception that occurs:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: type of: org.oz.report.Report; nested exception is org.hibernate.QueryException: could not resolve property: type of: org.oz.report.Report
Caused by: org.hibernate.QueryException: could not resolve property: type of: org.oz.report.Report
Name and version of the database you are using: Oracle 9i
I am trying to convert a fairly complicated HQL query to a criteria query. The existing HQL query is:
Code:
public Object doInHibernate(Session session) throws HibernateException {
String hql = "select stat, stat.type.typeID from " +
"Stats as stat where stat.report.organization in (:orgList) and " +
"stat.report.complete=true and stat.type in (:typeList) and " +
"stat.report.dateSubmitted = (select max(report2.dateSubmitted) from Report as report2 where " +
"report2.complete = true and report2.organization = stat.report.organization and report2.dateSubmitted <= :date)";
Query query = session.createQuery(hql);
query.setParameterList("orgList", organizations);
query.setParameterList("typeList", types);
query.setParameter("date", date);
return query.list();
}
My attempt to convert this to criteria is:
Code:
public Object doInHibernate(Session session) throws HibernateException {
Criteria crit = session.createCriteria(Stats.class, "stat");
crit.add(Restrictions.in("report.organization.organizationID", organizationIds));
crit.add(Restrictions.eq("report.complete", Boolean.valueOf(true)));
crit.add(Restrictions.in("type.typeID", typeIds));
DetachedCriteria crit1 = DetachedCriteria.forClass(Report.class, "report");
crit1.setProjection(Projections.max("report.dateSubmitted"));
crit1.add(Restrictions.eq("report.complete", Boolean.valueOf(true)));
crit1.add(Property.forName("report.organization.organizationID").eqProperty("stat.report.organization.organizationID"));
crit1.add(Restrictions.le("report.dateSubmitted", date));
crit.add(Subqueries.propertyEq("dateSubmitted", crit1));
return crit.list();
}
From what I understand, there were several fixes in version 3.2.6 of Hibernate that address DetachedCriteria and subqueries, but I am still having problems. I get the error listed above. Any advice or help would be greatly appreciated. Thanks!