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 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 Android Security Essentials Live Lessons this week in the Android 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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: bidirectional ManyToMany with java.util.Map
 
Similar Threads
Hibernate + Ternary Relation
Hibernate: Trouble with a bidirectional list
Best practice of mapping collection of enum
Persistence Example
ManyToMany relationship with extra field in the joinTable