-->
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: Complex sqlGroupProjection group
PostPosted: Thu Mar 24, 2011 12:32 pm 
Newbie

Joined: Thu Mar 24, 2011 12:23 pm
Posts: 1
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?


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.