[转]hibernate 使用criteria 进行子查询
hibernate criteria API exists subquery
SELECT *
FROM service_type
WHERE EXISTS (SELECT 1
FROM service
WHERE service.active = 1
AND service.is_57 = service_type.id)
Criteria criteria = session.createCriteria(ServiceType.class, "servicetype");
DetachedCriteria serviceCriteria = DetachedCriteria.forClass(Services.class, "service");
serviceCriteria.add(Restrictions.eq("ACTIVE", new Integer(1)));
serviceCriteria.add(Property.forName("servicetype.ID").eqProperty("service.IS_57"));
criteria.add(Subqueries.exists(serviceCriteria.setProjection(Projections.property("service.ID"))));
return criteria.list();
FROM service_type
WHERE EXISTS (SELECT 1
FROM service
WHERE service.active = 1
AND service.is_57 = service_type.id)
Criteria criteria = session.createCriteria(ServiceType.class, "servicetype");
DetachedCriteria serviceCriteria = DetachedCriteria.forClass(Services.class, "service");
serviceCriteria.add(Restrictions.eq("ACTIVE", new Integer(1)));
serviceCriteria.add(Property.forName("servicetype.ID").eqProperty("service.IS_57"));
criteria.add(Subqueries.exists(serviceCriteria.setProjection(Projections.property("service.ID"))));
return criteria.list();
[转载]http://workblognotes.blogspot.com/2010/09/hibernate-criteria-api-exists-subquery.html
相关推荐
LetonLIU 2020-03-28
东方咖啡屋 2020-02-14
LetonLIU 2019-12-23
qinkang 2019-11-09
surpassdream 2011-12-11
张浩BIT 2011-09-27
Franklyn 2017-01-01
hanyueqi 2019-06-30
康慧欣 2015-09-08
minerk 2019-06-30
逆流而上的鲤鱼 2013-07-19
xhljames 2012-12-07
frank0 2012-08-14
longxx 2012-07-09
阳光丶不锈 2012-07-09
zhongranxu 2019-06-28
Lendor 2012-04-25