-->
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.  [ 2 posts ] 
Author Message
 Post subject: writing sub query inside aggregate function
PostPosted: Mon Jul 12, 2004 7:38 am 
Newbie

Joined: Sun Apr 18, 2004 2:29 am
Posts: 18
hi
i have to write a pretty complex query which use aggregate functions for sum calculations.i need to write sub query inside aggregate function count().i am using an appropriate constructor to select new instances.
i have written the following query . please analyse it and give me suggestion. its urgent.


String stringQuery = "select new PeriodicallyLogonDto(" +
"select distinct pl1.employee from PeriodicallyLogonDto pl1," +
"count(from PeriodicallyLogonDto pl2 where pl2.logonStatus=:paramP)," +
"count(from PeriodicallyLogonDto pl3 where pl3.logonStatus=:paramA)," +
"count(from PeriodicallyLogonDto pl4 where pl4.logonStatus=:paramL)," +
"count(from PeriodicallyLogonDto pl5 where pl5.logonStatus=:paramV)) " +
"from PeriodicallyLogonDto dto where dto.logonDateType between :param2 " +
"and :param3";

Query query = session.createQuery(stringQuery);
query.setString("paramA", "A");
query.setString("paramL", "L");
query.setString("paramV", "V");
query.setString("paramP", "P");
query.setDate("param2", dto.getPeriodFromType());
query.setDate("param3", dto.getPeriodToType());

return query.list();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 7:41 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Unfortunately, any subqueries are not allowed in new Foo(). This might change with Hibernate3. Use a createSQLQuery().

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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

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.