wood burning stoves
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "bidirectional ManyToMany with java.util.Map" Watch "bidirectional ManyToMany with java.util.Map" New topic

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,


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
It's not a secret anymore!