Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

bidirectional ManyToMany with java.util.Map

 
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.
 
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.

 
It's never done THAT before. Explain it to me tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic