After loading an object, it's collection member variables are null.

May be the titld isn't so clear but I'll think of something later. I just need to write this down as not to forget it later on.


When you persist a bean that contains a collection (List, Set..etc). Retrieving that bean will give always give you a null collection by default.


So we need to overcome this. I didn't personally overcome it very well. I'm not good with Datanucleus but here is my solution.


In your persisted bean, mark your collection as the following example:



@Persistent(defaultFetchGroup = "true")
private Set permissions;


Then when you retrieve your object, call the getter of that collection. And then you'll have your bean with the collection initialized.


The trick is have your persistable bean marked as detatchable:

@PersistenceCapable(detachable = "true")public class UserInfo{/*...*/}





Then "detatch" the object before you close the persistence manager.
p = persistenceManager.detachCopy(p);


If you have a better solution please post it here.

Comments

Popular posts from this blog

Testing SOAP services using pingdom