Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help persisting a Many to Many Relation in JPA  RSS feed

Enrique Castro
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We Want to persist a many to many table with EclipseLink, we have just tried by setting the collections and persist but it returns error cause it seems that is requesting for all of the collections in the hierarchy, we are doing this cause the system did not mapped that table cause it has all of its fields as foreign keys so instead of that it set the @JoinTable and set a collection of the other table.....obviously we do not have any entity to persist so we would like to know How does JPA EclipseLink do to persist when the table has a Many to Many Relation and the table has not been you have any idea...

James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you are doing. Perhaps include your classes/annotations and your error, and the code you use to get the error.
Enrique Castro
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok this is what we are doing, we have mapped a database i will let you know what we have exactly:

firstly we are using netbeans 6.5.1 with eclipselink

a table called "customers" and other one called "catdetails"
the relation in between them is many to many
so we have an association table called "custcatalog".

* the custcatalog columns are foreign keys to customers and catdetails
so when we went ahead with netbeans to mapping... it generated all of the entities as usual
but we realized table custcatalog was not mapped so instead of that it put into the "customers" table the annotation @ManyToMany ,@joinTable with @joinColumns for "catdetails",
and "custcatalog" has the @ManyToMany and then set a Collection

i mentioned above the situation comes when i want to persist "custcatalog" for example a customer has for us a category and we store all of the categories in "custcatalog" where all the categories for all of the applications are so custcatalog has specifics categories for a "customers" so when i want to change a category for a customer for example class "A" "B or "C"
i have to store it in the database in the custcatalog table but the issue comes to persist into that table when there is no entity for .

i will show you the pieces of code for those entities:


@JoinTable(name = "Customers", joinColumns = {@JoinColumn(name = "CODE", referencedColumnName = "CODE")}, inverseJoinColumns = {@JoinColumn(name = "SIS", referencedColumnName = "SIS"), @JoinColumn(name = "CAT", referencedColumnName = "CAT"), @JoinColumn(name = "COR", referencedColumnName = "COR")})
private List<MgnCatdetails> catdetailsCollection;

@ManyToMany(cascade=CascadeType.ALL, mappedBy="CatdetailsCollection")
private List<Customers> customersCollection;

and i tried to persist in the following ways :

firstly i set the collection i want for the "Customers" with the right values and when persisting it shows an error:

Catdetails deta=
new BigInteger(this.txt_code.getText()),new BigInteger("0"), new BigInteger("90")).get(0);
List<Catdetails> detail=new ArrayList<Catdetails>();

//here we set the PK with the updated value for the category
CatdetailsPK cdetpk=new CatdetailsPK();
cdetpk.setCodsis(new BigInteger("0"));
cdetpk.setCodcat(new BigInteger("90"));
cdetpk.setCodcor(new BigInteger("10"));
//here we set the pk updated
//here we add to the arraylist<Catdetails> the new detail
//here the collection is set
//here we persist the entity
try {

} catch (Exception e) {
Logger.getLogger(Customers.class.getName()).log(Level.SEVERE,"There was an error... ", e);
}//end catch

"IOP00810257: (MARSHAL) Could not load class com.application.ejb.customers.entities.Catdetails"
org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 257 completed: Maybe

also was trying lazy but did not work same error, any idea.


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!