I have a domain object with several transient fields that contain complex POJOs. When the domain object is saved, I want to serialize these objects to XML (using Xstream), and store them into a PersistentMap in my database.
So I created a @PrePersist/@PreUpdate method on my domain object, and in those methods serialize the values and place them into the persistent map in the domain object. When the em.merge () is called, I can see the values get serialized, the map gets updated, but the actual values saved are the original values, not the updated ones.
From drilling into the Hibernate source, it appears that after the @PreUpdate, the default event handler for merge events copies the original associations over the ones that I changed in my PreUpdate method.
I've also tried using the Hibernate Interceptors and overriding the onSave method, but the result is that same (all of the relationships get copied from the original object to the result object, thus overwriting my changes).
Is this supposed to work this way? Is there some setting I can make in the configuration that will alter this behaviour? Is there some other way to accomplish what I need to do?
Any pointers would be greatly appreciated.
Thanks
|