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 tableB = new HashSet();
..
(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 tableA = new HashSet();
..
(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 results1 = (List) query1.execute();
TableA tableA= results1.get(0);
Query query2 = pm.newQuery(TableB.class);
List results2 = (List) 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)" 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 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.Datasto