This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes bidirectional ManyToMany with java.util.Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "bidirectional ManyToMany with java.util.Map" Watch "bidirectional ManyToMany with java.util.Map" New topic
Author

bidirectional ManyToMany with java.util.Map

Bupjae Lee
Ranch Hand

Joined: May 14, 2007
Posts: 107


I want to make bidirectional ManyToMany relationship between PhotoInfo and UserInfo.
Moreover, I want to track when each PhotoInfo--UserInfo relationship is established.

However, this attempt fails with following exception:



How can I annotate this relationship properly?
Thanks in advance.
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Both sides of a bi-directional @ManyToMany must be @ManyToMany, you cannot use @ElementCollection, or @Temporal.

You must make the Date the key not the value for what you are trying to do to work.

But it might be better to map an Entity to the join table instead (UserPhotoRelationship), see,

http://en.wikibooks.org/wiki/Java_Persistence/ManyToMany#Mapping_a_Join_Table_with_Additional_Columns

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Bupjae Lee
Ranch Hand

Joined: May 14, 2007
Posts: 107
Because it is possible to have same timestamp for user-photo relationship,
I couldn't use Date as the key of map.

Instead, I decided to create a "mapping" entity like this, and it works perfectly.
Thanks for answering.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bidirectional ManyToMany with java.util.Map