Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Not able to create entity after changing the primary key(JPA does not allow changing primary key for it's own reason.I am tyring to work it around by first removing the entity and then creating it back with changed primary key. However, when I try to pers)
Not able to create entity after changing the primary key [message #1058762] Tue, 14 May 2013 19:37 Go to next message
Eclipse UserFriend
Here is my sample program

================
Entity myentity = entityManager.find(class, key);

entityManager.remove(myentity);

entityManager.flush();

myEntity.setId(xyz) // id is primary key

entityManager.persist(myentity);
entityManager.flush();

========

I even tried, detaching entity (as well entityManager.clear()) but that did not help either, so basically i tried this too



Entity myentity = entityManager.find(class, key);

entityManager.remove(myentity);

entityManager.flush();

entityManager.detach(myentity);

myEntity.setId(xyz) // id is primary key

entityManager.persist(myentity);
entityManager.flush();



I am using eclipse link 2.3.2. can someone please tell me how to make this work?

Deepak
Re: Not able to create entity after changing the primary key [message #1058789 is a reply to message #1058762] Wed, 15 May 2013 02:34 Go to previous messageGo to next message
Eclipse UserFriend
Just want to add that I am getting following error when I am trying to persist the entity (one removed) with different primary key

The attribute [xxxxx] of class [MyEntity] is mapped to a primary key column in the database. Updates are not allowed.
Re: Not able to create entity after changing the primary key [message #1060016 is a reply to message #1058789] Wed, 22 May 2013 10:30 Go to previous message
Eclipse UserFriend
You cannot change an object's id. Instead create a new object, or clone/copy the object.
Previous Topic:Convert varchar to nvarchar for specific columns only.
Next Topic:NPE in DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:978)
Goto Forum:
  


Current Time: Tue Jul 08 03:43:23 EDT 2025

Powered by FUDForum. Page generated in 0.08328 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top