Reputation: 1423
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
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