I have the usual parent - child OneToMany relationship:
@OneToMany(mappedBy = "mapType", cascade = CascadeType.ALL, orphanRemoval = true)
public List<Child> getChildren() {
return c开发者_开发百科hildren;
}
I have fairly standard use cases:
Must delete children on persist- this works fine.
Add new children by adding to collection. This works fine for already persisted parents, but does not work for new parents. EntityManager.merge however does persist the new parent with the new children.
Why would adding new children not work for new Parent objects? They're definitely there before persist is called.
I'm on Hibernate 3.6.6 by the way.
Try to add this attribute in @OneToMany
annotation fetch = FetchType.EAGER
. Default value is LAZY. It'll be helpful because hibernate will be manage collection permanently then you make changes.
精彩评论