Hi Jason,

I could solve my previous problem. But now i am facing some other
problem with many to many relationship tables.

My schema looks as follows:

 TableA ---> TableC <----- TableB
which means there is many to many relationship between TableA &
TableB. So i want TableA and TableB primary keys  into TableC as
foreign key.

TableA class looks as follows:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class TableA implements Serializable{
 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Key id;
   ......
 @Persistent(defaultFetchGroup="true")
 private Set<Key> tableB = new HashSet<Key>();
 ......
  (some getter & setter)

TableB class looks as follows:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class TableB implements Serializable{
 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 private Key id;
   ......
 @Persistent(defaultFetchGroup="true")
 private Set<Key> tableA = new HashSet<Key>();
 ......
 (some getter & setter)

TableC class looks as follows:
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class TableC implements Serializable{
 @PrimaryKey
 @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 private Key id;

 @Persistent
 private TableA tablea;

 @Persistent
 private TableB tableb;
 .....
 (some getter & setter)

 While adding data into TableC i use following code:

 Query query1 = pm.newQuery(TableA.class);
 List<TableA> results1 = (List<TableA>) query1.execute();
 TableA tableA= results1.get(0);

Query query2 = pm.newQuery(TableB.class);
List<TableB> results2 = (List<TableB>) query2.execute();
TableB tableB= results2.get(0);

tableA.add(tableB);
tableB.add(tableA);

At this point TableA and TableB values are getting update but while
entering data into TableC the problem comes.
TableC tableC = new TableC();
tableC.setTableA(tableA);
tableC.setTableB(tableB);
pm.makePersistent(tableC);  --> at this point it gives me "A parent
cannot be established or changed once an object has been persisted."

Can you please tell me were i am going wrong?

Thanks
Anita

On Sep 15, 3:54 am, "Jason (Google)" <apija...@google.com> wrote:
> From the error message, it sounds like the parent isn't getting set
> correctly. You'll need to share some of your code in order for me to help
> you further -- what does your Release class look like and how are you
> persisting it?
>
> - Jason
>
> On Sat, Sep 12, 2009 at 4:36 AM, Anita <an...@ensarm.com> wrote:
>
> > Hi Jason,
>
> > Our schema looks as follows:
> >  ProductType 1--------->M Product 1-------->M Release
>
> > Data is inserting into Release table. But while fetching data from
> > release table i am getting following exception:
>
> > Field com.ensarm.server.domain.Release.products should be able to
> > provide a reference to its parent but the entity does not have a
> > parent.  Did you perhaps try to establish an instance of
> > com.ensarm.server.domain.Release as the child of an instance of
> > com.ensarm.server.domain.Products after the child had already been
> > persisted?
> > org.datanucleus.exceptions.NucleusUserException: Field
> > com.ensarm.server.domain.Release.products should be able to provide a
> > reference to its parent but the entity does not have a parent.  Did
> > you perhaps try to establish an instance of
> > com.ensarm.server.domain.Release as the child of an instance of
> > com.ensarm.server.domain.Products after the child had already been
> > persisted?
> >        at
> > org.datanucleus.store.appengine.DatastoreRelationFieldManager.lookupParent
> > (DatastoreRelationFieldManager.java:302)
> >        at
>
> > org.datanucleus.store.appengine.DatastoreRelationFieldManager.fetchRelationField
> > (DatastoreRelationFieldManager.java:289)
> >        at
> > org.datanucleus.store.appengine.DatastoreFieldManager.fetchObjectField
> > (DatastoreFieldManager.java:271)
> >        at org.datanucleus.state.AbstractStateManager.replacingObjectField
> > (AbstractStateManager.java:1197)
> >        at com.ensarm.server.domain.Release.jdoReplaceField(Release.java)
> >        at com.ensarm.server.domain.Release.jdoReplaceFields(Release.java)
> >        at org.datanucleus.state.JDOStateManagerImpl.replaceFields
> > (JDOStateManagerImpl.java:2772)
> >        at org.datanucleus.state.JDOStateManagerImpl.replaceFields
> > (JDOStateManagerImpl.java:2791)
> >        at
> > org.datanucleus.store.appengine.DatastorePersistenceHandler.fetchObject
> > (DatastorePersistenceHandler.java:349)
> >        at org.datanucleus.store.appengine.query.DatastoreQuery.entityToPojo
> > (DatastoreQuery.java:384)
> >        at org.datanucleus.store.appengine.query.DatastoreQuery.entityToPojo
> > (DatastoreQuery.java:345)
> >        at org.datanucleus.store.appengine.query.DatastoreQuery.access$700
> > (DatastoreQuery.java:96)
> >        at org.datanucleus.store.appengine.query.DatastoreQuery$5.apply
> > (DatastoreQuery.java:454)
> >        at org.datanucleus.store.appengine.query.DatastoreQuery$5.apply
> > (DatastoreQuery.java:453)
> >        at
> > org.datanucleus.store.appengine.query.StreamingQueryResult.resolveNext
> > (StreamingQueryResult.java:137)
> >        at org.datanucleus.store.appengine.query.StreamingQueryResult
> > $1.computeNext(StreamingQueryResult.java:163)
> >        at
> > org.datanucleus.store.appengine.query.AbstractIterator.tryToComputeNext
> > (AbstractIterator.java:132)
> >        at org.datanucleus.store.appengine.query.AbstractIterator.hasNext
> > (AbstractIterator.java:127)
> >        at org.datanucleus.store.appengine.query.StreamingQueryResult
> > $AbstractListIterator.hasNext(StreamingQueryResult.java:229)
> >        at com.ensarm.server.servlet.GetData.getRelease(GetData.java:87)
> >        at com.ensarm.server.servlet.GetData.doGet(GetData.java:32)
> >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
> >        at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
> >        at
> > org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
> > 487)
> >        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
> > (ServletHandler.java:1093)
> >         at
> > com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter
> > (TransactionCleanupFilter.java:43)
> >         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
> > (ServletHandler.java:1084)
> >        at com.google.appengine.tools.development.StaticFileFilter.doFilter
> > (StaticFileFilter.java:124)
> >         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
> > (ServletHandler.java:1084)
> >         at org.mortbay.jetty.servlet.ServletHandler.handle
> > (ServletHandler.java:360)
> >        at org.mortbay.jetty.security.SecurityHandler.handle
> > (SecurityHandler.java:216)
> >        at org.mortbay.jetty.servlet.SessionHandler.handle
> > (SessionHandler.java:181)
> >        at org.mortbay.jetty.handler.ContextHandler.handle
> > (ContextHandler.java:712)
> >        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
> > 405)
> >        at
> > com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle
> > (DevAppEngineWebAppContext.java:54)
> >         at org.mortbay.jetty.handler.HandlerWrapper.handle
> > (HandlerWrapper.java:139)
> >        at com.google.appengine.tools.development.JettyContainerService
> > $ApiProxyHandler.handle(JettyContainerService.java:313)
> >         at org.mortbay.jetty.handler.HandlerWrapper.handle
> > (HandlerWrapper.java:139)
> >        at org.mortbay.jetty.Server.handle(Server.java:313)
> >        at
> > org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
> > 506)
> >        at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete
> > (HttpConnection.java:830)
> >         at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
> >        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
> >        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
> >        at org.mortbay.io.nio.SelectChannelEndPoint.run
> > (SelectChannelEndPoint.java:396)
> >        at org.mortbay.thread.BoundedThreadPool$PoolThread.run
> > (BoundedThreadPool.java:442)
>
> > What should be done for this problem?
>
> > Anita
--~--~---------~--~----~------------~-------~--~----~
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 google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to