Hibernate criteria projection distinct

user1450954 picture user1450954 · Aug 20, 2012 · Viewed 47.3k times · Source

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

Answer

Ramaraj Karuppusamy picture Ramaraj Karuppusamy · Aug 20, 2012
Criteria criteria = 
    session.createCriteria(S2.class)
           .add(Restrictions.eq("s2Tc","601"))
           .add(Restrictions.ne("s2Txcd",""))
           .setProjection(Projections.distinct(Projections.property("s2Taxper")));