Okay, having conquered the first newbie hurdle of LazyInitializationException, now I am faced with the second-most-common issue: NonUniqueObjectException in a cascade saveOrUpdate.
I have a Submission table, that contains many child Product records, and each Product contains many ProductFiles.
In my app, I load a Submission from the database using Hibernate, then populate it's children and grandchildren with Products and ProductFiles created at run-time, then attempt to saveOrUpdate the Submission. All my hbm.xml mappings have default-cascade="save-update", so Hibernate attempts to insert the new Products and ProductFiles (or at least it should).
At this point, I receive a "NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.testProject.entities.ProductFile#0]".
I should note that the ProductFile entity's identifier is an Integer value, with a default (unsaved) value of zero. So here, it looks as though Hibernate is seeing a bunch of ProductFiles with the same ID (zero, since they are all unsaved), and is freaking out.
So how can I tell the Hibernate Engine that these objects are unsaved, and therefore not "identical"?
|