You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Srinivasan Krishnamoorthy <sr...@live.com> on 2009/10/04 13:15:34 UTC
Detach and Attach with XML serialization
Hi,
I have an issue with detaching and attaching the entities when serialized as XML.
I have an entity which is serialized as XML and sent to client in a stateless fashion. (I have not serialized some relations)
When the XML is sent back to me I have to attach/merge it and do an update.
I can pass on the Id and version and get it back from the client. But not the Detach state field Object.
So I have 2 solutions below.
Solution 1
After receiving the updated XML, do a find with the primary key and update the values and persist.
Drawbacks:
1. I have to do a find for every update.
2. I have to copy each and every variable of the object. This I need to do for every object that I use.
3. I use JAXB for constructing the java object, but not able to merge it directly because I don't have detach state field info.
Solution 2 (Not sure if this will work, havent tried it)
After the entity is detached, store the detach state field (serialized Object) in a database with Id and classname as composite primary key.
Before attach, fetch this Object from DB and set it on to the field, and then do an attach.
Drawbacks:
1. DB operation is required for detach and attach.
Advantage:
Solution is generic. (if it works :-) )
Please advise me on the best choice, or if there is a better way, please suggest me the same.
Best Regards,
Srinivasan Krishnamoorthy
_________________________________________________________________
News, views and inimitable perspectives – On MSN India, you get an all-round view of things that matter.
http://in.msn.com