网上搜集到的,先记录下来以备以后整理
方法一:
@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();
}
方法二:
方法一:
@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();
}
方法二:
- public ArrayList<T> EmptyBaia(){ ??
- ????????DetachedCriteria subconsulta = DetachedCriteria.forClass(Usuarios.class).setProjection(Property.forName("baia")); ??
- ????????ArrayList<T> baia = (ArrayList<T>) this.session.createCriteria(this.classe).add(Property.forName("numero").notIn(subconsulta)).list(); ??
- ????????return baia; ??
- ????}?
本文介绍了两种从数据库查询特定条件下的列表的方法。第一种方法使用@Transactional注解和Hibernate查询API实现,第二种方法则利用DetachedCriteria进行子查询并结合Hibernate Criteria API完成。这两种方法均适用于在Java应用中操作复杂的数据集合。
951

被折叠的 条评论
为什么被折叠?



