Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Bi-directional entity-keyed map(Can it be done?)
Bi-directional entity-keyed map [message #1751617] Wed, 11 January 2017 22:54
Marco Dorfliger is currently offline Marco DorfligerFriend
Messages: 43
Registered: January 2015
Member
Consider this scenario:
index.php/fa/28106/0/

A User may have multiple Projects, and a Project contains multiple Users.

Additionally, each relationship has a participation level (VIEWER, MEMBER or MANAGER) which grants the user different privileges depending on their role. The participation level is an enumeration.

In JPA, I have implemented this relationship on the Project as a map with the User entity as its key, and a Participation enum as its value, as follows:

@Entity
public class Project {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    // fields...

    @ElementCollection
    @CollectionTable(name = "user_x_project")
    @MapKeyJoinColumn(name = "user_id")
    @Column(name = "participation_level_uid")
    @Enumerated(EnumType.STRING)
    private Map<User, Participation> userAssignments;

  // getters and setters...

}

The above code works fine. What I haven't been able to achieve is the inverse relationship.

I have tried this:
@Entity
@Table(name = "users")
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    // fields...

    @ManyToMany(mappedBy = "userAssignments")
    private Map<Project, Participation> projectAssignments;

    // getters and setters...

}

But when it runs, I get this output:
Exception Description: [class User] uses a non-entity [class Participation] as target entity in the relationship attribute [field projectAssignments].

I think I need to indicate somehow that the key of the map is to be used as the target entity, but I'm not sure how. Any ideas?
  • Attachment: Oeu3o.png
    (Size: 8.96KB, Downloaded 102 times)
Previous Topic:Moxy xpath predicate not working
Next Topic:ConcurrencyManager.releaseDeferredLock
Goto Forum:
  


Current Time: Fri Dec 15 10:32:27 GMT 2017

Powered by FUDForum. Page generated in 0.01859 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software