hibernate使用迫切内连接检索策略时,查询结果可能会包含重复元素,可以通过一个HashSet来过滤重复元素:
List result=session.createQuery("from Customer c inner join fetch c.orders o where c.name like 'T%'").list();
HashSet set=new HashSet(result);
for(Iterator it=set.iterator();it.hasNext();){
Customer customer=(Customer)it.next()
}
List result=session.createQuery("from Customer c inner join fetch c.orders o where c.name like 'T%'").list();
HashSet set=new HashSet(result);
for(Iterator it=set.iterator();it.hasNext();){
Customer customer=(Customer)it.next()
}