1

I'd like to convert this DB2 SQL Statement into Hibernate Criteria statements. I'm new to Hibernate and find difficulties to convert to hibernate criteria.

My SQL

SELECT DISTINCT (USER_ID) FROM USERS  
where STATUS='EXECUTED' and TRANSACTION_TIME  
BETWEEN (SELECT current timestamp -1 MONTH FROM SYSIBM.SYSDUMMY1)  
and (SELECT current timestamp FROM SYSIBM.SYSDUMMY1)

However i tried to get the where clause but i not sure how to use distinct and between clause in hibernate criteria

Criteria criteria = session.createCriteria(Users.class);
criteria.add(Restrictions.eq("status", "EXECUTED"));
List<Users> usersList  = criteria.list();

I wanted to use it since it gives me cleaner code.

Thanks in advance.

Senthil RS
  • 271
  • 3
  • 8
  • 17
  • check this [answer 1](http://stackoverflow.com/questions/10731723/how-to-add-distinct-in-hibernate-criteria) or this [answer 2](http://stackoverflow.com/questions/300491/how-to-get-distinct-results-in-hibernate-with-joins-and-row-based-limiting-pagi), the shortest solution is like `criteria.setProjection(Projections.distinct(Projections.id()));` – AntJavaDev Aug 01 '16 at 06:55

0 Answers0