Note that there are some explanatory texts on larger screens.

plurals
  1. POOne-To-Many child has already been persisted without parent
    text
    copied!<p>I'm using the Google App Engine in combination with the Google Web Toolkit to write a bug tracker (to see what the technologies are capable of).</p> <p>Modelled after Google Code's issue tracker, I decided that an issue can have 0 or more labels, that can be defined beforehand (let's say in the settings).</p> <p>The label class (CustomLabel):</p> <pre><code>@PersistenceCapable(identityType = IdentityType.APPLICATION) public class CustomLabel implements Serializable { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") private String encodedKey; @Persistent @Extension(vendorName="datanucleus", key="gae.pk-id", value="true") private Long keyId; /** * label caption. */ @Persistent private String caption; // Unimportant getters / setters } </code></pre> <p>Now the parent class (Issue):</p> <pre><code>@PersistenceCapable(identityType = IdentityType.APPLICATION) public class Issue implements Serializable { private static final long serialVersionUID = 1L; @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Long id; // Replacing the Long key by this key doesn't make a difference // @PrimaryKey // @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) // @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") // private String encodedKey; @Persistent private String summary; @Persistent private String description; @Persistent private ArrayList&lt;CustomLabel&gt; labels; // Other details } </code></pre> <p>When I'm trying to persist a new Issue with existing CustomLabels I get the following exception:</p> <pre><code>org.datanucleus.exceptions.NucleusUserException: Detected attempt to establish Issue(11) as the parent of CustomLabel(1) but the entity identified by CustomLabel(1) has already been persisted without a parent. A parent cannot be established or changed once an object has been persisted. </code></pre> <p>How can this be solved? I cannot use Key's and create an unowned relationship, since I'm sending the objects to the GWT front-end (which is compiled to Javascript and com.google.appengine.api.datastore.Key isn't supported). Besides that would break referential integrity, which is undesirable. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload