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.