This actually sounds like it is working correctly. makePersistent() is the "save" call. You should not be calling this until all the changes you intend on making have been made to the object you are persisting.
Another option you have is to detach the object, but this has its own gotchas as well. On Sat, Dec 26, 2009 at 11:55 AM, ailinykh <[email protected]> wrote: > Ok. I narrowed down the problem. > What I want is to maintain unowned relationship. > I have simple class with set of Long (they are supposed to be ids of > other objects): > > @PersistenceCapable(identityType = IdentityType.APPLICATION) > public class Dummy { > @Override > public String toString() { > StringBuilder sb = new StringBuilder(); > sb.append(id); > sb.append(", Keys "); > sb.append(idSet); > return sb.toString(); > } > @PrimaryKey > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > private Key id; > @Persistent > Set<Long> idSet = new HashSet<Long>(); > public void addId(Long id){ > idSet.add(id); > } > public Key getKey(){ > return id; > } > } > > The problem is- if I create new object of class Dummy and make it > persistent > @Test > public void testIt(){ > Dummy p = new Dummy(); > > PersistenceManager pm = PMF.get().getPersistenceManager(); > p.addId((long)1); > pm.makePersistent(p); > p.addId((long)2); > Key id = p.getKey(); > pm.close(); > pm = PMF.get().getPersistenceManager(); > Dummy pp = pm.getObjectById(Dummy.class, id); > System.out.println(pp); > } > > it ignores all changes to idSet made after makePersistent() call. So, > for code above I have: > Dummy(1), Keys [1] > Key 2 is lost. > > But when I restore by > pm.getObjectById(Dummy.class, id); > everything looks good. I can add and more ids and restore them > successfully: > > @Test > public void testIt(){ > Dummy p = new Dummy(); > > PersistenceManager pm = PMF.get().getPersistenceManager(); > p.addId((long)1); > pm.makePersistent(p); > p.addId((long)2); > Key id = p.getKey(); > pm.close(); > pm = PMF.get().getPersistenceManager(); > Dummy pp = pm.getObjectById(Dummy.class, id); > System.out.println(pp); > > pp.addId((long)3); > pp.addId((long)4); > System.out.println(pp); > pm.close(); > pm = PMF.get().getPersistenceManager(); > Dummy ppp = pm.getObjectById(Dummy.class, id); > System.out.print(ppp); > } > > here I have what I'm supposed to have: > > Dummy(1), Keys [1] > Dummy(1), Keys [1, 3, 4] > Dec 26, 2009 1:43:29 PM org.datanucleus.ObjectManagerImpl close > INFO: Outstanding nontx update being committed to datastore > Dummy(1), Keys [1, 3, 4] > > So, it looks like it is not possible to maintain unowned relationship. > Did anybody create unowned relationship? > > Thank you, > Andrey > > > > On Dec 26, 12:10 am, ailinykh <[email protected]> wrote: > > Hello, everybody! > > I try to achieve simple thing - storing a set of keys. > > I have two classes: > > > > @PersistenceCapable(identityType = IdentityType.APPLICATION) > > public class Account { > > > > @PrimaryKey > > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > private Key id; > > > > @Persistent(mappedBy="account") > > List<Label> labels = new ArrayList<Label>(); > > > > @Persistent > > Set<Key> ids = new HashSet<Key>(); > > > > } > > > > @PersistenceCapable(identityType = IdentityType.APPLICATION) > > public class Label { > > @PrimaryKey > > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > private Key id; > > > > @Persistent > > private Account account; > > > > } > > > > I created new Account > > > > Account a = new Account(); > > then added two Labels to Account, then added Label's keys to ids set. > > As result I have for ids: > > [Account(1)/Label(4), Account(1)/Label(3)] > > > > which looks correct. > > > > Then I called > > pm.makePersistent(a), > > pm.close(); > > > > I created new instance of PersistenceManager and restore Account > > object. > > I get back two Labels, but their keys (ids set) is empty. > > What did I do wrong? > > > > Thank you, > > Andrey > > -- > > You received this message because you are subscribed to the Google Groups > "Google App Engine" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-appengine%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-appengine?hl=en. > > > -- Ikai Lan Developer Programs Engineer, Google App Engine -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
