title: AppEngine datastore: "Object with id ... is managed by a different Object Manager"
body: <p>I'm using the Google AppEngine, with Java.  When I use some datastore features, I'm getting an error message:  </p>
  
  <pre><code>Object with id "edvaltt.Teacher@64064b" is managed by a different Object Manager
  </code></pre>
  
  <p>I don't know what this means or how to fix it or where to look for documentation on this error. Can anyone help me?  The code I'm using is:</p>
  
  <pre><code>@PersistenceCapable(identityType = IdentityType.APPLICATION)
  public class School {
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private String shortname;
  
  @Persistent
  private String fullname;
  
  @Persistent
  @Order(extensions = @Extension(vendorName="datanucleus", key="list-ordering", value="code asc"))
  private List&lt;Teacher&gt; Teachers;
  
  ...
  
  public Teacher FindOrCreateTeacher(String code)
  {
      // Can we find the teacher without any database code?
      Teacher newTeacher = FindTeacher(code);
      if (newTeacher != null)
          return newTeacher;
  
      // Create the teacher:
      PersistenceManager pm = PMF.get().getPersistenceManager();
      Transaction tx = pm.currentTransaction();
      try {
          tx.begin();
          for (Teacher teacher : Teachers) {
              if (teacher.getCode() == code) {
                  tx.rollback();
                  return teacher;
              }
          }
          newTeacher = new Teacher(code);
          Teachers.add(newTeacher);
          pm.makePersistent(newTeacher);
          pm.makePersistent(Teachers);
          tx.commit();
      } finally {
          tx.commit();
      }
      return newTeacher;
  }
  </code></pre>
  
  <p>I believe that "<code>private List&lt;Teacher&gt; Teachers;</code>" refers to an "owned, one to many" relationship.</p>