gui
gui

Reputation: 35

How to write this sql in DetachedCriteria in Hibernate

select * from Confirmation where (fee + extra) >= 12 ;

Hi guys, I want to know an easy way to get the total of two columns (fee + extra) which may possibly passed inside like :

DetachedCriteria criteria = DetachedCriteria.forClass(Confirmation.class)

criteria.add(Subqueries.propertyGe(".....", 12)); 

Upvotes: 0

Views: 1030

Answers (1)

Zeus
Zeus

Reputation: 6576

You can try the following

DetachedCriteria criteria = DetachedCriteria.forClass(Confirmation.class)

criteria.setProjection(Projections.sqlProjection("fee + extra",new String(){"fee"},new Type(){Hibernate.Integer}));

Not tested, but, you will get the idea.

Upvotes: 1

Related Questions