I seem to be having issues saving a basic Parent / Child object graph using EJB 3.0 Jboss. My Parent table (Parent) has a single Primary Key called parent_id. My Child table (Child) has a foreign key to the Parent table.
The parent_id value is automatically generated from the database upon record insert into the Parent table (I'm using Oracle). When Jboss/Hibernate attempts to persist the entire object graph, Hibernate throws an exception indicating that the parent_id in the Child cannot be null, which I completely understand, however, I was under the assumption that JPA/Hibernate would automatically propagate the parent_id down to the Child records upon insert of the Parent. I obviously cannot set this value when building out the object graph b/c I do not have this value yet.
Also, In Parent entity I have OneToMany annotation in which cascade element is set to "PERSIST".
Its only a Unidirectional relationship from parent to child. Child doesnt have reference to Parent.
I create Parent. then I create child entities and set the collection of children in Parent, and I finally persist Parent, assuming the children will get persisted since cascade is turned on.
However I get batch update exception.
Caused by:
java.sql.BatchUpdateException: ORA-02291: integrity constraint (TEST.FK01_PRNT) violated - parent key not found
integrity constraint (TEST.FK01_PRNT) violated - parent key not found
Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
Has anybody out there run into this issue or have any suggestions?