标签归档:DetachedCriteria

Hibernate实体关联查询方法

            在项目中经常要多个实体中查询数据,下面使用Hibernate实体关联查询方法:

DetachedCriteria criteria =DetachedCriteria .forClass(Org.class);
DetachedCriteria staffCeiteria = DetachedCriteria.forClass(Staff.class);
staffCeiteria.setProjection(Property.forName("id"));
staffCeiteria.add(Restrictions.ilike("name",createName,MatchMode.ANYWHERE));
criteria.add(Property.forName("created").in(staffCeiteria));