0

I have one @Entity called Team as

    @Entity
    @Table(name="projects_participants")
    public class Team {

        @Id`enter code here`
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column
        private int id;



    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }


    @Column(name="participants_id")
    private int participants_id;

    public int getParticipants_id() {
        return participants_id;
    }

    public void setParticipants_id(int participants_id) {
        this.participants_id = participants_id;
    }









    /*
    @CollectionOfElements 
    private Set<Projects> projectsParticipant;

    @ManyToMany(fetch = FetchType.LAZY,mappedBy = "team")
    public Set<Projects> getProjectsParticipant() {
        return projectsParticipant;
    }


    public void setProjectsParticipant(Set<Projects> projectsParticipant) {
        this.projectsParticipant = projectsParticipant;
    }
        */
}

I have another bean name Projects like

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "projects_participants", joinColumns = { 
        @JoinColumn(name = "project_id") }, 
        inverseJoinColumns = { @JoinColumn(name = "participants_id",referencedColumnName="participants_id")})
public Set<Team> getTeam() {
    return team;
}

public void setTeam(Set<Team> team) {
    this.team = team;
}

It works fine but the problem is project_participants Table has project_id and id of Team table. But I want project_id and Participants_id of Team table. project_participants Table is as below

enter image description here

participants table as * enter image description here

Finally What I Want is table project_participants should have project_project_id and participants_id (not team_id).Thanx in advance.

Milople Inc
  • 399
  • 1
  • 8
  • 34

1 Answers1

0

It seems to me, that you're trying to model a m:n relationship, but not using the right annotation and principles.

1) Use @ManyToMany in combination with @JoinTable to model the m:n relationship like documented in the jee5 api.

2) Don't model relationships to other objects via ID columns like you did with participants_id. With JPA you work with objects, not with their IDs, so your column would be a Participant.

Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96