I have a parent which consists of a set of children. The relationship in the database is maintained by having a foreign key column in the child table. I am using Oracle database and the primary keys are generated by using sequence. I am trying to add a new parent object together with the associated set of children objects to the database by using the hibernate cascade save but I have no success up to now.
In the parent class (Product.java)
In the child class (Picture.java)
FYI, this is a bi-directional one-to-many mapping. "lse09lse06id" is the foreign key column in the child entity table.
My driver class:
I truncated my code a bit for brevity sake. I actually execute the driver code in a Spring MVC controller. Anyway my problem is whenever the code is executed I will have the following exception:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not insert: [ghash.lse.domain.Picture]; SQL [insert into lse09pictures (lse09content, lse09date_created, lse09date_deleted, lse09date_updated, lse09is_deleted, lse09lse06id, lse09id) values (?, ?, ?, ?, ?, ?, ?)]; constraint [CSSE3005GG.LSE09PICTURES_FK]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [ghash.lse.domain.Picture]
One of the nested exceptions caught:
java.sql.SQLException: ORA-02291: integrity constraint (CSSE3005GG.LSE09PICTURES_FK) violated - parent key not found
Any help is very much appreciated! If you need more details I am more than willing to post them up.