Hello everyone,
I'm having a problem with refreshing a detached entity in hibernate. I'll try and keep my explanation of the situation as simple as possible.
I have three classes. Class A, B and C. All classes are entities. Class A contains an object of Class B with its CascadeType set to refresh only. Class B contains a list of Class C objects, also with a CascadeType of refresh only and its fetch type is set to lazy (it cannot be eager). These classes reside in a web application that has the job of serving up serialized copies of Class A objects in XML form.
Since serializing a PersistentBag object is a problem I set the list of Class C objects inside Class B to null before serialization. The important thing is the relationship of Class B objects to Class A. So when the client receives the XML output it includes all members of Class A as well as all members of Class B with the exception of the list of Class C objects.
I then deserialize the Class A object on the client side, make some change to it and push it back to the webapp to perform an update. Inside Class A's DAO I first perform a refresh on the Class B member before performing the merge.
The problem I am experiencing is that when the DAO performs the refresh on Class B I get an error from hibernate claiming that the object is not managed by hibernate. Now as said previously the intent here is to maintain the relationship of Class A to B so any missing information inside Class B should be irrelevant (except of course the ID that links the two database tables together).
Does refresh not do what I think it does? How do I make this work? Is my only option to pull the list of Class C objects and serialize them as well? If so its a lot of unnecessary data being sent back and forth from webapp to client. There must be a better way.
Thanks in advance for any help!
|