• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bidirectional ManyToMany with java.util.Map

 
Bupjae Lee
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic