MountainClimb / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

JDO java cascade unidirectional mapping problem #200

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Patient {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key patientID;

    @Persistent
    private String patientName;

    @ForeignKey
    @Persistent
    private Genders genderID;

    @Persistent
    private Date patientBirthDate;
}

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Genders {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key genderID;

    @Persistent 
    private String genderText;
}
What is the expected output? What do you see instead?
I use this code:
Patient patient = new Patient("someName", pm.getObjectById(
                    Genders.class, 7), new Date(), new );

And i got this exception:
Detected attempt to establish Patient(420) as the parent of Genders(7) but
the entity identified by Genders(7) has already been persisted without a
parent.  A parent cannot be established or changed once an object has been
persisted.

What version of the product are you using? On what operating system?
Eclipse

Please provide any additional information below.
Please help to solve this problem

Original issue reported on code.google.com by tavel...@gmail.com on 29 Mar 2010 at 8:39

GoogleCodeExporter commented 8 years ago
You persisted an object (Genders) with no parent. Thereafter it cannot have a 
parent (by GAE rules). You tried to assign a parent to it (and break GAE 
rules). 

Solution : persist the parent first.

Original comment by googleco...@yahoo.co.uk on 21 Sep 2011 at 1:01