Announcement Announcement Module
Collapse
No announcement yet.
@ManyToMany relationship attributes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ManyToMany relationship attributes

    Hi

    I have two entities Employee and Project in my application and there is many to many relationship between them. The application uses JPA and Hibernate. I have three tables:
    Code:
    employee: empId, name
    project: projId, name
    emp_proj: empId, projId
    
    class Employee{
       ...
       @ManyToMany
       @JoinTable(.....)
       Collection<Project> projects;
       ....
    }
    
    class Project
       ...
       @ManyToMany(mappedby="projects")
       private Collection<Employee> employees;
       ....
    }
    Now I want to add information that who assigned a particular project to the employee, so the modified table looks like this:

    Code:
    emp_proj: empId, projId, assignee.
    Since assignee is not the attribute of any of the two entities [i.e. employee or project] i can't access it.

    One solution to this is that I make another entity for table emp_proj and break the relationship into two OneToMany relationships employee -> emp_proj and project -> emp_project.

    Can anyone suggest a better solution by which i can access the attributes of the relationship?

    Thanks
    Amit Khanna

  • #2
    Hello,

    You get the correct answer : transform your n-n relationship to two 1-n relationship.

    There is no better choice.

    Comment

    Working...
    X