与两个实体共享数据集合

时间:2013-07-18 09:04:16

标签: hibernate share hibernate-annotations

我在互联网上找不到关于我的问题的答案,所以我希望在这里有一些信息: - )

仅供参考,这是我的第一堂课,Attribut:

@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;

现在,我在我的数据库中有一个已经保存的Set of LocString的attribut。 我想创建一个新的Attribut(具有一个新的id),但使用完全相同的LocString Set(数据库中的相同引用,内存中的相同引用,相同的id)。当我尝试保存我的attribut时,我有以下例外:

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

如何避免此异常。是否可以使用hibernate?

非常感谢您的帮助

克莱门特

0 个答案:

没有答案
相关问题