thanks for the reply
thatmikewilliams wrote:
If you set the users collection of role to a new (empty) array list while the session is open then hibernate will interpret that as deleting all the users from that role.
When i have not asked the object to be persisted or merged, why should hibernate assume that i am cleaning up the relation?
Your requirements sound a little odd. Calling getUsers should return the users if there are some. Returning an empty list instead just strikes me as wrong. Either you shouldn't be calling that method in your scenario or it should be pre-initialised with the users form the role.
I have two modes in which an object is populated
- notDeep ==> where only its attributes and relations marked eager are populated
- deep ==> where its attributes and all relations are populated.
My requirement is to serialize POJOs to XML outside the session in the client code. So, i iterate thru all attributes and relations to build the XML. If i find a relation populated, i serialize the relation to XML as well.
Now, i get this lazyInitError if i access a PersistentBag outside session, which is valid. I am looking for a solution to avoid that exception and have the POJO not have any Persistence pointers/references
in non-deep mode
<role name="rr">
</role>
in deep mode
<role name="rr">
<user name="ss"/>
<user name="dd"/>
</role>
i did download a HibernateCleaner piece of code, but when i run that it removes all peristence references but it always populates ManyToMany relations.
i hope my requirement was clear enough. Your thoughts will be appreciated.