Reputation: 53
I've got following code:
@Entity
public class Incident {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String incidentId;
@Persistent
@Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
private Long keyId;
@OneToMany(mappedBy="incident")
@OrderBy("requestId")
@JoinColumn(name="INCIDENT_ID")
public List<ServiceRequest> requests;
...
}
@Entity
public class ServiceRequest {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String requestId;
@Persistent
@Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
private Long keyId;
private Incident incident;
...
}
Scenario of using it is firstly create and persist ServiceRequest and then create a Incident and add to it existing ServiceRequest - but when I tried to persist an Incident I've got following error Caused by: org.datanucleus.exceptions.NucleusUserException: Object with id "agxzbWFydGNpdHlhZ2hyFAsSDlNlcnZpY2VSZXF1ZXN0GAEM" is managed by a different Object Manager
Upvotes: 1
Views: 642
Reputation: 603
I'll sugest you to start as follows, and then tell you to study deeply the doc regarding all the datastore, JDO Stuff. Then thank Google. :-)
You must use the same persistence manager to do all your read / create / save / update tasks at once. Meaning that in the same method or code block, you have to :
The thing is, if you work with more than one Entity, you need to use the same PersistenceManager instance.
Upvotes: 1