In my understanding,
In case of a one to many bidirectional association, with inverse set to true and foreign key set to NOT NULL. If saving the parent is to be cascaded to its children then all is needed is setting the parent pointer in child, adding child to parent and then inserting parent. Inserting parent will then be cascaded to its children which will also be inserted. Thats well and good for a bidirectional association.
My problem is with the case of a one to many association that is not bidirectional, with inverse set to false and foreign key set to
NOT NULL, and saving the parent is to be
cascaded to its children. Now when I add child to parent and then insert parent Hibernate throws the SQLException that
Quote:
Cannot insert NULL in foreign key column in Child table
When at the application level the child has been added to parent then why doesnt Hibernate insert the foreign key while inserting child record. I guess the pattern Hibernate follows is: Insert Child record and then update Child record with the foreign key. Why cant all this be done in one single Child record insert in which the foreign key is also inserted
Is there a way around this problem?
Thanx in advance for suggestions and tips