user1999453
user1999453

Reputation: 1423

how to build a hibernate multiple restriction In query with Criteria

I am currently building a query and I have to use the Criteria object from hibernate. Basically my native query is below:

select * from HDR where app_no in (select appNo from perm where code in (select code from access where appCode = 'P' and catId in :dymanicParam))

Any idea how to build the native query stated above by using org.hibernate.Criteria?

Thanks a lot for response.

Upvotes: 0

Views: 187

Answers (1)

yeahseol
yeahseol

Reputation: 385

Try do this

DetachedCriteria accessCriteria = DetachedCriteria.forClass(Access.class)
         .setProjection(Property.forName("code"))
         .add(Restrictions.eq("appCode", "P"))
         .add(Restrictions.eq("catId", dymanicParam));

DetachedCriteria permCriteria = DetachedCriteria.forClass(Perm.class)
         .setProjection(Property.forName("appNo"))
         .add(Property.forName("code").in(accessCriteria))

DetachedCriteria criteria = DetachedCriteria.forClass(HDR.class)
         .add(Property.forName("app_no").in(permCriteria))

// criteria.getExecutableCriteria(session).list();

Upvotes: 1

Related Questions