-->
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: How to write in Criteria Query
PostPosted: Tue Jan 12, 2010 3:09 am 
Newbie

Joined: Tue Jan 12, 2010 3:00 am
Posts: 1
Hi,
Please help me out to write the following in Criteria or Example Query :-

StringBuilder SQLquery=new StringBuilder();
SQLquery.append(" select dbo.getSearchString(qr.id) as queryString,qr.resultCount as resultCount, qr.dateFound as dateFound from SolrQLog.QueryResult qr where dateFound >= ? and dateFound <= ? group by qr.id, resultCount, dateFound order by ");

if(sortType == null){
SQLquery.append(" resultCount");
}else if(sortType.equalsIgnoreCase("Search String")){
SQLquery.append(" queryString");
}else if(sortType.equalsIgnoreCase("Date")){
SQLquery.append(" dateFound");
}else{
SQLquery.append(" resultCount");
}


List<SearchResults> allList = getSession().createSQLQuery(SQLquery.toString())
.addScalar("queryString", Hibernate.STRING)
.addScalar("resultCount", Hibernate.INTEGER)
.addScalar("dateFound", Hibernate.DATE)
.setResultTransformer(Transformers.aliasToBean(SearchResults.class))
.setString(0, fromDate)
.setString(1, toDate)
.list();

In the above getSearchString is a DB function and sortType is the parameter passed to that DAO method.

Thanks,
Utpal


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.