-->
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: Having clause for Criteria
PostPosted: Mon Dec 22, 2008 2:12 pm 
Newbie

Joined: Tue May 22, 2007 2:12 am
Posts: 9
Hi all,

I'm using Projections.count on a particular property in my criteria query.
Further , i want to retrieve only those records where the above count is greater than 50.

My SQL is something like this

Code:
select count(called_number) from call_dets
group by called_number having count(called_number) > 50 ;


The criteria looks like --

Code:
public List getCallDetsForReport(Map objectArgs)
   {
      logger.info("start of call details records");
      List dataList = null;
      try
      {
         List calledNumList = new ArrayList();
         String callingNum = null;//(String)objectArgs.get("callingNumber");
         String calledNum = null;//(String)objectArgs.get("calledNum");
         //calledNumList = null;//(List)objectArgs.get("calledNumberList");
         callingNum = "9829576509";
         Session hibSession = getSession();
         Criteria criteria = hibSession.createCriteria(CallDets.class);
         criteria.setProjection(Projections.projectionList()
               .add(Projections.count("calledNumber").as("countCalled"))
               .add(Projections.property("callingNumber").as("callingNum"))
               .add(Projections.property("calledNumber").as("calledNum"))
               .add(Projections.groupProperty("calledNumber"))
               );
         criteria.add(Restrictions.eq("callingNumber",callingNum));
         criteria.setResultTransformer(new AliasToBeanResultTransformer(CallDetailsRecCustomVO.class));
         dataList = criteria.list();
         System.out.println("the list size here is "+dataList.size());
      }
      catch(Exception e)
      {
         logger.error("the error has occured"+e);
         e.printStackTrace();
      }
      return dataList;
   }


As per my knowledge , having clause is not available in criteria API.
Can you provide any work around for this.


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.