my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes Help persisting a Many to Many Relation in JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Help persisting a Many to Many Relation in JPA" Watch "Help persisting a Many to Many Relation in JPA" New topic
Author

Help persisting a Many to Many Relation in JPA

Enrique Castro
Greenhorn

Joined: Jun 01, 2010
Posts: 7
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 mapped....do you have any idea...


thanks.-
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Not sure what you are doing. Perhaps include your classes/annotations and your error, and the code you use to get the error.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Enrique Castro
Greenhorn

Joined: Jun 01, 2010
Posts: 7
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:

****CUSTOMERS:

@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")})
@ManyToMany
private List<MgnCatdetails> catdetailsCollection;

****CATDETAILS
@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=
this.customerFacade.getSimpleCat(
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
deta.catdetailsPK(cdetpk);
//here we add to the arraylist<Catdetails> the new detail
detail.add(deta);
//here the collection is set
customer.setCatdetailsCollection(detail);
//here we persist the entity
try {
customerFacade.edit(customer);

} catch (Exception e) {
stat=true;
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
at com.sun.corba.ee.impl.logging.ORBUtilSystemException.couldNotFindClass(ORBUtilSystemException.java:9679)

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

Thanks.-


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help persisting a Many to Many Relation in JPA
 
Similar Threads
Eager Fetching a Polymorphic SET
Pass JPA entities across tiers?
EJB Question. Add a new column to Many-to-many relation generated table.
Many-To-Many Writing Problem
JPA: preventing overlapping calendar events by locking a table?