-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Need Help Converting from HQL to Criteria
PostPosted: Tue Apr 08, 2008 11:21 am 
Newbie

Joined: Tue Oct 10, 2006 3:27 pm
Posts: 4
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.