【发布时间】:2015-04-27 20:30:14
【问题描述】:
考虑以下几点:
@Entity
public class MainEntity {
@OneToOne(orphanRemoval = true, cascade = CascadeType.ALL)
private ChildEntity childEntity;
}
@Entity
public class ChildEntity {
@OneToMany(cascade = CascadeType.ALL)
@LazyCollection(FALSE)
private List<AnotherEntity> otherEntities;
}
现在,当我第一次打电话时
final ChildEntity anewChild = new ChildEntity();
anewChild.addOtherEntity(anotherEntity); //Several Entities can be added here
mainEntity.setChildEntity(anewChild);
EntityManager.persist(mainEntity);
一切正常,然后我在事务完成很久之后进行一些更新。
final ChildEntity anotherNewChild = new ChildEntity();
anotherNewChild.addOtherEntity(anotherEntity); //Several Entities can be added here
mainEntity.setChildEntity(anotherNewChild);
//A log of LOG.info(mainEntity); shows all fields appropriately set
//At some point during merge operation, the new ChildEntity will need to be persisted.
//According to my logs, an invocation of EntityManager.persist(anotherNewChild) occurs, during as the merge is propagated to the new entity.
//At this point is where the ChildEntity.otherEntities is detected to be null
return EntityManager.merge(mainEntity);
问题在于,使用坚持,
List<AnotherEntity>
不为空且不为空,在合并时,
List<AnotherEntity>
为空
我正在通过 ejb 远程调用执行此操作。
休眠 4.3.6 野蝇 8.1.0 jpa 2.1
我这里有什么遗漏吗?
使用以下代码重现问题:
https://github.com/marembo2008/hibernate-jpa-bug
在 Hibernate 问题跟踪器上打开了一个问题。
【问题讨论】:
标签: java hibernate jpa orm hibernate-mapping