在我的 hibernate 实体对象上为@OneToMany 或@ManyToMany 属性使用Set 或Collection 有什么区别?
Hibernate 是否会根据您选择的不同来映射事物?
最佳答案
在 hibernate 上下文中,以下是您将使用 Set 而不是 Collection 的场景:-
"From Order as orders left fetch join orders.orderLineItems as orderLineItems ORDER BY orders.id DESC"
它返回重复项,因此使用散列集删除它们。
Query query = session.getNamedQuery("OrdersAndLoadLineItems");
设置 set = new LinkedHashSet();
set.addAll(query.list());
返回集;
这取自 Hibernate FAQ 链接是 http://www.hibernate.org/117.241.html
关于java - hibernate 中 Set 和 Collection 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/504337/