File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Many-To-Many Writing Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Many-To-Many Writing Problem" Watch "Many-To-Many Writing Problem" New topic
Author

Many-To-Many Writing Problem

Carlos Conti
Ranch Hand

Joined: Apr 21, 2010
Posts: 114
Hi all,
I am persisting with EclipseLink 1.1
I have 'apparently' successfully set up a m-t-m relationshiop between two entities as follows (orm.xml):



Tables are correct in the database. In fact the EntityManager loads correcty. And when running the persist method, everything works fine, no errors, but the join table data is not being written. The data belonging to both entities is successfully updated, but not its join information.
I tried modifying the Cascade properties for both of them as you can see, but still no luck.

I am pretty sure I am missing something but can't figure out what, since Eclipse is not giving any clue any more.

I would greatly appreciate your advise!
Many thanks in advance,


Carlos Conti
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Make sure you are adding to both sides of the ManyToMany relationship. If you only add to one side, then your object model is not correct.
Only the side without the mapped-by is persisted, so if you are only adding to the other side, then nothing will be written to the database.


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Carlos Conti
Ranch Hand

Joined: Apr 21, 2010
Posts: 114
You are absolutely right!
Thanks! it worked at first run. I understand. If both collections are not reciprocally referenced the object model is incorrect, hence the persistence task won't fullfill. I find however strange that in that case no exception is thrown at all. In anycase I will bear that in mind for future ocasions.

Thanks again.

Carlos Conti.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Many-To-Many Writing Problem