surinder-insonix / datanucleus-appengine

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

Unable to merge object with gae.pk-id #322

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
@Entity
@Table(name="parent")
public class Parent implements Serializable {

    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
    private String id;

...

@Entity
@Table(name="child")
public class Child implements Serializable
{

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
    private String id;

    @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
    private Long longId;

    @Extension(vendorName="datanucleus", key="gae.parent-pk", value="true")
    private String parentId;
...
2.
Parent parent = new Parent();
entityManager.persist(parent);

Child child = new Child();
child.setParentId(parent.getId());
entityManager.persist(child);

3.
Child child = entityManager.find(Child.class, child.getId());
entityManager.merge(child);

What is the expected output? What do you see instead?
Error:
javax.persistence.PersistenceException: Attempt was made to modify the primary 
key of an object of type Child identified by key 
parent(5669544198668288)/child(5629499534213120)  Primary keys are immutable.  
(New value: child(5629499534213120)

What version of the product are you using? On what operating system?
App Engine 1.9.15

Please provide any additional information below.

Original issue reported on code.google.com by pavel.se...@gmail.com on 1 Nov 2014 at 1:21

GoogleCodeExporter commented 8 years ago
3.
Child child = entityManager.find(Child.class, child.getId());
entityManager.detach(child);
entityManager.merge(child);

Original comment by pavel.se...@gmail.com on 1 Nov 2014 at 1:23