Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate criteria projection distinct

Tags:

Hi i want to write a query using criteria : The following query has to be created using criteria:

"Select Distinct(s2Taxper) from S2 where s2Tc='601' AND s2Txcd!=''"

thanks in advance

like image 525
user1450954 Avatar asked Aug 20 '12 05:08

user1450954


People also ask

How projection is used in hibernate criteria?

To put it simple, Hibernate Projections are used in order to query only a subset of the attributes of an entity or group of entities you're querying with Criteria. You can also use Projections to specify distinct clauses and aggregate functions like max , sum and so on.


1 Answers

Criteria criteria = 
    session.createCriteria(S2.class)
           .add(Restrictions.eq("s2Tc","601"))
           .add(Restrictions.ne("s2Txcd",""))
           .setProjection(Projections.distinct(Projections.property("s2Taxper")));
like image 156
Ramaraj Karuppusamy Avatar answered Oct 21 '22 15:10

Ramaraj Karuppusamy