hibernate关于in和not in的查询


方法一:
@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
public List<OpUsrrole> OpUsrroleExList(List<OpUsrrole> grprole) {
ArrayList<Long> ids = new ArrayList<Long>();
for(int i=0;i<grprole.size();i++){
ids.add(grprole.get(i).getIRoleid());
System.out.println(ids.get(i).toString());
}
Query q = sessionFactory.getCurrentSession().createQuery("select distinct rl from OpUsrrole rl where rl.IRoleid not in(:ids)");
q.setParameterList("ids", ids);
return q.list();

}

方法二:
  1. public ArrayList<T> EmptyBaia(){   
  2.         DetachedCriteria subconsulta = DetachedCriteria.forClass(Usuarios.class).setProjection(Property.forName("baia"));   
  3.         ArrayList<T> baia = (ArrayList<T>) this.session.createCriteria(this.classe).add(Property.forName("numero").notIn(subconsulta)).list();   
  4.         return baia;   
  5.     } 

你可能感兴趣的:(Hibernate,query)