java - Reference key issue while doing many to many relationship using @ElementCollection, @MapKeyJoinColumn -


I am trying on a lot of relationships, the team member can work on several projects, and many team members in one project The table structure can be as follows,

  (ID integer always generated as primary identifier key (starting with 12, increase increment from 3), name varchar ( 50) table TBL_TEAM_MEMBER_ONE (ID integer table TBL_PROJECT_ONE is the primary identity as we make Starting with Esha's went keys generated (7 increments of 5), name varchar (50), salary integer) Table EMP_PRJ_CADRE (MEMBER_ID integer reference TBL_TEAM_MEMBER_ONE, PRJ_ID integer reference TBL_PROJECT_ONE, cadre varchar (10), barrier PK_001_EMP_TEAM make primary key (MEMBER_ID, PRJ_ID))   

Here I have just created a new table to store the relationship, now please follow the employee unit,

  @Entity @Table (name = "TBL_TEAM_MEMBER_ONE") Public class EmployeeEntityFour applies Serializable {public EmployeeEntityFour () {} public EmployeeEntit YFour (string empName, int salary) {... ..} @ ID @ generatedValue (strategy = GenerationType.INDNTITY) @ Column (name = "id") private int empId; @ Column (name = "NAME") private string empName; @column (name = "salary") private integer empSal; @ElementCollection (speed = FetchType.LAZY) @CollectionTable (name = "EMP_PRJ_CADRE") @MapKeyJoinColumn (name = "PRJ_ID") @Column (name = "cadre") private Map & LT; ProjectEntityOne, string & gt; EmployeeCadre; ... ..}   

Follow the mapping for the project unit,

  @Entity @Table (name = "TBL_PROJECT_ONE") public class ProjectEntityOne Applies Serializable {Public ProjectEntityOne () {} Public ProjectsInteen A (string name) {this.projectName = name; } @ID @ Generated Values ​​(strategy = generation type.INTTI) @column (name = "id") private integer project; @ Column (name = "NAME") private string project name; @ElementCollection (speed = FetchType.LAZY) @CollectionTable (name = "EMP_PRJ_CADRE") @MapKeyJoinColumn (name = "MEMBER_ID") @Column (name = "cadre") private Map & LT; EmployeeEntityFour, string & gt; EmployeeCadre; .... ..}   

The code written in the main method is as follows,

  ProjectEntityOne proj = New ProjectEntityOne ("City Grand Central") ; Click the & lt; EmployeeEntityFour, string & gt; Cadmap = new hashmop & lt; Employee Entrepreneur, String & gt; (); Cadmapoptop (new employee antitifor ("Muelleri Muthu", 34000), "senior software engineer"); Cadremappop (new employee's Entitouch ("Gopalakrishna Rajanathan", 64000), "Software Engineer"); Cadmap.pot (new employee's Antitifour ("Premna Swaminathan", 94000), "Project Manager"); Proj.setEmployeeCadre (cadreMap); Em.persist (proj);   

But I do not have a column in getting an error

  Error: "Projektitaijn_aidi 'table or' APP Apeepiaarpiarjisiadiara is not Vitiai.   

When I have specified @MapKeyJoinColumn in both organizations, I get an error as an inappropriate column for the third table.

While I am missing

On employeeCadre in EmployeeEntityFour a @JoinColumn (Name = "MEMBER_ID") and you will also need a @JoinColumn (name = "PRJ_ID") in ProjectEntityOne Employee Cadre.

But, I will not model it in this way. First of all you can not do a bi-directional element collation mapping, and ElementClon can be owned by one side only. The best solution is to define a cadre unit mapping for the EMP-PRJ_CADRE table, and both sides will have OneToMany for this, and it will have many tutorials for each.

Alternatively you can use a ManyToMany with a MapKeyColumn, but I think that you would be better than being an institution.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -