hi, I am facing same problem. I referred to above given link as well but could not succeed. Can anyone please provide me with a complete example.
Thanks, Anita On Jul 18, 11:50 am, George Simon <[email protected]> wrote: > Thanks Max. I followed the notes and its working fine. > > On Fri, Jul 17, 2009 at 6:44 AM, Max Ross > <[email protected]<maxr%[email protected]> > > > wrote: > > Many to many relationships are not yet supported. Suggested workaround is > > here: > > >http://code.google.com/appengine/docs/java/datastore/relationships.ht... > > > Thanks, > > Max > > > On Fri, Jul 17, 2009 at 9:28 AM, GS <[email protected]> wrote: > > >> I am getting an issue in many to many relationships "A parent cannot > >> be established or changed once an object has been persisted." > > >> My Code is given below > >> @PersistenceCapable(identityType = IdentityType.APPLICATION, > >> detachable="true") > >> public class A { > >> �...@primarykey > >> �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > >> private Key key; > > >> �...@persistent > >> private String property; > > >> public A(Key key, String property) { > >> super(); > >> this.key = key; > >> this.property = property; > >> } > > >> �...@persistent > >> private Set<B> bObjs = new HashSet<B>(); > > >> public void addB(B bObj) { > >> bObjs.add(bObj); > >> } > >> } > >> ------------- > >> @PersistenceCapable(identityType = IdentityType.APPLICATION, > >> detachable="true") > >> public class B { > >> �...@primarykey > >> �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > >> private Key key; > > >> �...@persistent > >> private String prop; > > >> public B(Key key, String prop) { > >> super(); > >> this.key = key; > >> this.prop = prop; > >> } > > >> �...@persistent > >> private Set<A> aObjs = new HashSet<A>(); > > >> public void addA(A a){ > >> aObjs.add(a); > >> } > >> } > > >> ------ > >> class MyServlet{ > > >> public boolean createData() { > >> PersistenceManagerFactory pmf = PMF.get(); > >> PersistenceManager pm = pmf.getPersistenceManager(); > >> pm.setDetachAllOnCommit(true); > >> //javax.jdo.Transaction tx = pm.currentTransaction(); > > >> Object[] aIds = new Object[3]; > >> Object[] bIds = new Object[3]; > > >> try { > > >> A aObject1 = new > >> A(KeyFactory.createKey(A.class.getSimpleName(), > >> "a1001"), "Property for A(1)"); > >> A aObject2 = new > >> A(KeyFactory.createKey(A.class.getSimpleName(), > >> "a1002"), "Property for A(2)"); > >> A aObject3 = new > >> A(KeyFactory.createKey(A.class.getSimpleName(), > >> "a1003"), "Property for A(3)"); > > >> B bObject1 = new > >> B(KeyFactory.createKey(B.class.getSimpleName(), > >> "b1001"), "Property value for B(1) > >> "); > >> B bObject2 = new > >> B(KeyFactory.createKey(B.class.getSimpleName(), > >> "b1002"), "Property value for B(2) > >> "); > >> B bObject3 = new > >> B(KeyFactory.createKey(B.class.getSimpleName(), > >> "b1003"), "Property value for B(3) > >> "); > > >> pm.makePersistent(aObject1); > >> pm.makePersistent(aObject2); > >> pm.makePersistent(aObject3); > > >> pm.makePersistent(bObject1); > >> pm.makePersistent(bObject2); > >> pm.makePersistent(bObject3); > > >> aIds[0] = aObject1.getKey(); > >> aIds[1] = aObject2.getKey(); > >> aIds[2] = aObject3.getKey(); > > >> bIds[0] = bObject1.getKey(); > >> bIds[1] = bObject2.getKey(); > >> bIds[2] = bObject3.getKey(); > > >> tx = pm.currentTransaction(); > >> tx.begin(); > >> aObject1.addB(bObject1); > >> aObject1.addB(bObject2); > > >> bObject3.addA(aObject2); > >> bObject3.addA(aObject3); > >> tx.commit(); > >> } catch (Exception e) { > >> log.warning("Error while adding" + e.getMessage()); > >> if (tx.isActive()) { > >> tx.rollback(); > >> } > >> } finally { > >> pm.close(); > >> } > > >> } > > >> successfully created the 6 objects. Problem in setting the > >> relationships. > >> Any ideas? > >> Thanks in Advance > > >> George > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" 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-java?hl=en -~----------~----~----~----~------~----~------~--~---
