如何为以上查询转换休眠条件查询?

时间:2018-07-11 13:00:28

标签: java sql hibernate criteria

select * from ( select * from department) d 

如何为上述查询转换休眠条件查询?

1 个答案:

答案 0 :(得分:0)

扩展:

import org.hibernate.Criteria; 
import org.hibernate.Session; 
import org.hibernate.criterion.Restrictions; 
import javax.persistence.EntityManager;

创建:

@PersistenceContext 
private EntityManager entityManager; 
public Session getSession() { 
    return (Session) this.entityManager.getDelegate(); 
}

然后执行以下操作:

Criteria crit = this.getSession().createCriteria(YourClass.class); return crit.list();

糟糕:此YourClass是实体类