I have following model:
@PersistenceCapable(detachable="true")
public class User {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent(defaultFetchGroup = "true", mappedBy="owner")
@Element(dependent = "true")
private List<Offer> offers;
@Persistent(defaultFetchGroup = "true")
@Element(dependent = "true")
public List<Update> pendingUpdates;
//..(setters & getters omitted)
}
@PersistenceCapable(detachable="true")
public class Offer{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent(defaultFetchGroup="true")
private User owner;
@Persistent(defaultFetchGroup = "true")
private List<Key> waitingForConfirmationUsers;
//..(setters & getters omitted)
}
And now in code:
public void enqueueUserToOffer(Key offerKey, Key user){
final PersistenceManager pm = PMF.getPersistenceManager();
Offer offer = pm.getObjectById(Offer.class, offerKey);
offer.getWaitingForConfirmationUsers.add(user) // #2
User owner = offer.getOwner();
///!!!
owner.getPendingUpdates().add(new Update()); //<--this line (#1)
//!!!
pm.makePersistent(offer);
}
After line marked as '<--this line' 'offer' object is somehow reloaded('waitingForConfirmationUsers' seems like new empty List object) and user object added to 'waitingForConfirmationUsers' in line #2 disappears.
Could anyone explain what has happened?
(Issue experienced on dev-server)
Regars, M
@EDIT:
workaround for this problem is to touch owner's waitingForConfirmationUsers List just after fetching offer:
public void enqueueUserToOffer(Key offerKey, Key user){
final PersistenceManager pm = PMF.getPersistenceManager();
Offer offer = pm.getObjectById(Offer.class, offerKey);
offer.getOwner().getPendingUpdates();
offer.getWaitingForConfirmationUsers.add(user) // #2
User owner = offer.getOwner();
///!!!
owner.getPendingUpdates().add(new Update()); //<--this line (#1)
//!!!
pm.makePersistent(offer);
}