我在互联网上找不到关于我的问题的任何答案,所以我希望在这里有一些信息:-)
仅供参考,这是我的第一堂课,属性:
@Entity
@Table(name="T_ATTRIBUT")
public class Attribut implements Serializable{
private long id;
private Set<LocString> label = new HashSet<LocString>(0);
@ManyToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
public Set<LocString> getLabel() {
return label;
}
...
这是类 LocString :
@Entity
@Table(name="T_LOC_STRING")
public class LocString implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID")
private long id;
@Column(name="LOCALE")
private String locale;
@Column(name="VALUE")
private String value;
现在,我的数据库中有一个属性,其中包含一组已保存的 LocString。我想创建一个新的属性(具有新的 id),但使用完全相同的 LocString 集(数据库中的相同引用,内存中的相同引用,相同的 id)。当我尝试保存我的属性时,出现以下异常:
org.springframework.orm.hibernate4.HibernateSystemException: Found shared references
to a collection: com.nomia.onmap.model.Attribut.label; nested exception is
org.hibernate.HibernateException: Found shared references to a collection
我怎样才能避免这个异常。有可能与休眠有关吗?
非常感谢您的帮助
克莱门特