Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Many-To-Many Writing Problem

 
Carlos Conti
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Carlos Conti
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic