I'm trying to pull back a range of data based on a number of hours passed to a method. I take that number of hours, format starting and ending dates, calculate the timezone offset, and then attempt to set up criteria.
Code:
criteria.add(Restrictions.between("ctime", loRange, today));
criteria.add(Restrictions.eq("clientId", clientId));
criteria.add(Restrictions.gt("status", 0));
ProjectionList pl = Projections.projectionList();
pl.add(Projections.count("id"));
pl.add(Projections.sqlGroupProjection(String.format("to_char(%s_.ctime - " + offsetHours + "/24, 'YYYY-MM-DD H24') as ctime", criteria.getAlias()),
String.format("to_char(%s_.ctime - " + offsetHours + "/24, 'YYYY-MM-DD HH24')", criteria.getAlias()),
new String[] {"ctime"},
new Type[] {Hibernate.STRING}));
criteria.setProjection(pl);
criteria.addOrder(Order.asc(String.format("to_char(%s_.ctime - " + offsetHours + "/24, 'YYYY-MM-DD HH24')", criteria.getAlias())));
List < Object [] > count = this.hibernateTemplate.findByCriteria(criteria);
When I execute this code, I receive the following exception message:
Quote:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: to_char(this_ of: com.tfcci.ucs.signup.model.SignupUser; nested exception is org.hibernate.QueryException: could not resolve property: to_char(this_ of: com.tfcci.ucs.signup.model.SignupUser
When I execute the SQL statement this code should be generating by itself, the data is returned in the grouping format I'm looking for:
Quote:
select count(this_.id) as y0_, to_char(this_.ctime - 3/24, 'YYYY-MM-DD HH24') as ctime from ######_###### this_ where this_.ctime between to_date('2011-03-22 10:00:00','YYYY-MM-DD HH24:MI:SS') and to_date('2011-03-23 10:00:00','YYYY-MM-DD HH24:MI:SS') and this_.cli_id='-1000' group by to_char(this_.ctime - 3/24, 'YYYY-MM-DD HH24') order by to_char(this_.ctime - 3/24, 'YYYY-MM-DD HH24') asc
Any thoughts or ideas as to what I'm doing wrong?