问题描述:

I am using the following query on my table named as data

Query in native format

( select * from data where testId > (select max(testId) from data where out='1' ) order by time desc)

 DetachedCriteria subquery=DetachedCriteria.forClass(Data.class);

subquery.add(Restrictions.eq("out", true));

ProjectionList projections=Projections.projectionList();

projections.add(Projections.max("testId"));

subquery.setProjection(projections);

Criteria criteria = session.createCriteria(Data.class);

criteria.add(Subqueries.propertyGt("testId",subquery));

criteria.addOrder(Order.desc("time"));

I want to add the subquery only when the detached criteria's result is not null (i.e max(testId)!=null) because there will be a case that max(testId) is returned null i.e when database is empty.

how to do the above operation without using NATIVE SQL?

相关阅读:
Top