-->
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: Having clause in criteria
PostPosted: Sun Feb 24, 2008 11:14 pm 
Beginner
Beginner

Joined: Thu Dec 13, 2007 2:32 pm
Posts: 26
I have a query like this :
Code:

      /*
       *select  this_.department,
       *        sum(this_.salary)
       *    from Employee this_
       *       group by department
       *     having sum(salary) > 100
       *
       */


how do i execute this using criteria : ( i have this in mind , but it uses where clause instead of having )


Code:
Criteria critera = session.createCriteria(Employee.class).setProjection(Projections.projectionList()
                                             .add(Projections.sum("salary").as("sum_salary"))
                                             .add(Projections.groupProperty("department")));
      List<Object[]> emmployeeListWithHaving = critera.add(Restrictions.eq("sum_salary", 4000000)).list();



Sql generated :

Code:
    select
        sum(this_.SALARY) as y0_,
        this_.DEPARTMENT as y1_
    from
        EMPLOYEE this_
    where
        y0_=?
    group by
        this_.DEPARTMENT


Any thoughts / suggestions ?

_________________
Regards,
Vyas, Anirudh


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 8:13 am 
Beginner
Beginner

Joined: Thu Dec 13, 2007 2:32 pm
Posts: 26
I was going through JP with Hibernate and i found out that Having clause isnt available with Criteria API; was this added ? ( I checked JIRA issue thingie and it seems to be in "fixed" status ... if so, can someone point me to "new" syntax? )

_________________
Regards,
Vyas, Anirudh


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.