我有一个Java bean中的多对多关系。 当我使用List
定义我的变量时,如下所示:
@Entity
@Table(name="ScD")
public class Group extends Nameable {
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
@JoinColumn(name="b_fk")
private List<R> r;
//or
private Set<R> r;
我遇到了这个错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0'
...
当我使用Set
时,一切似乎都很顺利。
我想问的是,在使用多对多关系时,为了逻辑概念应该使用哪个,List
还是Set
(因为列表可能有重复项,而集合呢?但是考虑到性能和其他问题呢)?