Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

error while persisting many to many relationship object : Attempt to assign

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a scenario of persisting object with many to many relation. I have two classes Applicaiton and Person which has many to many relations with additional column, so mapped with third table ApplicationGroupMember.

The annotations are as below

public class Application{
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="APP_ID", insertable=false, updatable=false)
public long applicationId;

cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST})
private List<ApplicationGroupMember> persons;

public class Person {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="PRSN_ID", insertable=false, updatable=false)
private long personId;

cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST})
private List<ApplicationGroupMember> applications;

public class ApplicationGroupMember {
@Column(name="APP_ID", insertable=false, updatable=false)
private long applicationId;

@Column(name="PRSN_ID", insertable=false, updatable=false)
private long personId;

cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST})
@PrimaryKeyJoinColumn(name="APP_ID", referencedColumnName="APP_ID")
private Application application;

cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST})
@PrimaryKeyJoinColumn(name="PRSN_ID", referencedColumnName="PRSN_ID")
private Person person;

public class ApplicationPersonId {

private long applicationId;
private long personId;

I tried to load application object with two ApplicaitonGroupMember for two Person as below

Application app = new Application();
Person person1 = new Person();
Person person2 = new Person();
ApplicationGroupMember grp = new ApplicationGroupMember();

ApplicationGroupMember grp2 = new ApplicationGroupMember();


I am getting following error
<openjpa-1.2.0-r422266:683325 fatal user error> org.apache.openjpa.persistence.ArgumentException: Attempt to assign id "com.ApplicationGroupMember-com.ApplicationPersonId@0" to new instance "com.ApplicationGroupMember@4aa44aa4" failed; there is already an object in the L1 cache with this id. You must delete this object (in a previous transaction or the current one) before reusing its id. This error can also occur when a horizontally or vertically mapped classes uses auto-increment application identity and does not use a hierarchy of application identity classes.

I traced the sql, all insert statements are fine but the error occured only when transaction is about to commit. The above code works fine with one person.

I really appreciate, if anyone helps to fix the issue

Trust God, but always tether your camel... to this tiny ad.
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic