hibernate 4.3.0 @OneToMany orphanRemoval = true离开孤儿

时间:2013-05-17 17:15:50

标签: hibernate orphaned-objects

我发现很多关于orphanRemoval = true选项的讨论仍然留下了孤儿,但我似乎找不到正确答案。

我有一个Connector类,它在UniqueProperty类的List上有一个OneToMany关系

@OneToMany(cascade = CascadeType.ALL, orphanRemoval=true)
@LazyCollection(LazyCollectionOption.FALSE)
private List<UniqueProperty> uniqueProperties;

UniqueProperty有这个定义:

@Id
@Column(name = "id", length = 200, unique = true, nullable = false)
private String id;
private String name;
private String type;
@Column(unique=true)
private String value;

protected UniqueProperty(){}

我使用的是PostgreSQL数据库。 当我创建一个新连接器并添加一个UniqueProperty(name,valueA)时,它会在connector_uniqueproperty表中创建一行,并在uniqueproperty表中创建一行。 当我创建一个具有相同ID的新Connector实例(新的hibernate会话)并且这次不添加Unique属性时,session.saveOrUpdate(连接器)调用会从connector_uniqueproperty中删除相关行,但保留相关行uniqueproperty table(现在是一个孤儿)。

有关为何会发生这种情况的任何建议?

0 个答案:

没有答案