I am faced with the following issue:
I have two classes (e.g. Parent and Child). When I am updating a Parent object, the Child object is created in the database by cascade, so the the Child object receives an Id. Now Hibernate attempts to update Parent and fails due to some validation error (say I didn't define a name for the Parent) -- The validation is performed by calling a Hibernate ClassValidator inside a class implementing PreUpdateEventListener.
I now have a Parent object, pointing to a Child object which has an Id even though its creation in the database was rolled-back due to the validation error of Parent.
If I then fix the validation issue and try to update Parent again, a Foreign-Key constraint violation exception is thrown as Hibernate thinks the Child object already exists in the DB (it has an Id after all).
I'd like to know if Hibernate provides an out-of-the-box solution to this scenario.
Thanks in advance!
|