i have a Question about referencing ParentEntities from Child Entites ir If i have something like this:
Parent.java:
@Entity(name ="Parent")
If I am getting you correctly, according to EntityManager
, if you want it to manage the transaction's insert order your have to "tell him" that it should persist the children too. And you are not doing that, so "he" doesn't know what to persist, but your parent's child list is not empty so "he" takes it has correct but the stored value is null.
So you should consider do something like:
... begin, etc
em.persist(child)
em.persist(parent)
do what you want with the parent object here then commit and this should work for similar cases too.