Kwestia klucza referencyjnego podczas wykonywania wielu do wielu relacji przy użyciu @ElementCollection, @MapKeyJoinColumn

próbuję wielu do wielu relacji, członek zespołu może pracować nad wieloma projektami, a projekt może mieć wielu członków zespołu, struktura tabeli jest następująca,

create table TBL_PROJECT_ONE(
       id integer primary key generated always as identity(start with 12,increment by 3),
       name varchar(50)
)

create table TBL_TEAM_MEMBER_ONE(
    id integer primary key generated always as identity(start with 7,increment by 5),
    name varchar(50),
    salary integer
)

create table EMP_PRJ_CADRE(
    MEMBER_ID integer references TBL_TEAM_MEMBER_ONE,
    PRJ_ID integer references TBL_PROJECT_ONE,
    CADRE varchar(10),
    constraint PK_001_EMP_TEAM primary key (MEMBER_ID,PRJ_ID)
)

Tutaj stworzyłem nową tabelę tylko po to, aby przechowywać relację. Teraz proszę podążać za jednostką pracownika,

@Entity
@Table(name="TBL_TEAM_MEMBER_ONE")
public class EmployeeEntityFour implements Serializable{
   public EmployeeEntityFour(){}
   public EmployeeEntityFour(String empName,Integer salary){
   ...
   ..
   }
   @Id
   @GeneratedValue(strategy= GenerationType.IDENTITY)
   @Column(name="ID")
   private Integer empId;

   @Column(name="NAME")
   private String empName;

   @Column(name="SALARY")
   private Integer empSal;

   @ElementCollection(fetch= FetchType.LAZY)
   @CollectionTable(name="EMP_PRJ_CADRE")
   @MapKeyJoinColumn(name="PRJ_ID")
   @Column(name="CADRE")
   private Map<ProjectEntityOne,String> employeeCadre;
   ...
   ..
   .
}

Postępuj zgodnie z mapowaniem dla jednostki projektu,

@Entity
@Table(name="TBL_PROJECT_ONE")
public class ProjectEntityOne implements Serializable{
   public ProjectEntityOne(){}
   public ProjectEntityOne(String name){
     this.projectName = name;
   }

   @Id
   @GeneratedValue(strategy= GenerationType.IDENTITY)
   @Column(name="ID")
   private Integer projectId;

   @Column(name="NAME")
   private String projectName;    

   @ElementCollection(fetch= FetchType.LAZY)
   @CollectionTable(name="EMP_PRJ_CADRE")
   @MapKeyJoinColumn(name="MEMBER_ID")
   @Column(name="CADRE")
   private Map<EmployeeEntityFour,String> employeeCadre;
   ....
   ..
   .
}

W głównej metodzie testowanie napisanego kodu jest następujące:

ProjectEntityOne proj = new ProjectEntityOne("Citi Grand Central");        
Map<EmployeeEntityFour,String> cadreMap = new HashMap<EmployeeEntityFour,String>();
cadreMap.put(new EmployeeEntityFour("Murlinarayan Muthu",34000), "Senior Software Engineer");
cadreMap.put(new EmployeeEntityFour("Gopalkrishna Rajnathan",64000), "Software Engineer");
cadreMap.put(new EmployeeEntityFour("Premanna Swaminathan",94000), "Project Manager");

proj.setEmployeeCadre(cadreMap);

em.persist(proj);

ale otrzymuję błąd, który jest

ERROR: 'PROJECTENTITYONE_ID' is not a column in table or VTI 'APP.EMP_PRJ_CADRE'.

Gdy w obu obiektach podałem @MapKeyJoinColumn niż w przypadku, otrzymuję błąd jako niewłaściwa kolumna dla trzeciej tabeli.

Gdzie mnie brakuje

questionAnswers(2)

yourAnswerToTheQuestion