Can someone here help me with the following situation?
* I'm updating a detached object (an Entity)
* some of the properties which were previously null (such as Entity.email, of type EmailAddress) have now been set to new, unsaved objects
Is there some way to get Hibernate to automatically insert the new EmailAddress, even though I am updating the Entity? I've set the email property to cascade all, but that doesn't seem to work. So I changed my Entity DAO to detect that the EmailAddress is unsaved and save it manually.
This works, but I'm wondering whether it is the best way to do it. Also, it introduces a problem: if the transaction is rolled back, the ID is nevertheless still set on the unsaved EmailAddress, so if I try again to update the containing Entity I get a constraint violation. Is there an accepted way of avoiding this problem?
Kind regards,
Pepijn Schmitz
|