Apr 25, 2013

Hibernate OnetoMany mapping with composite key

Consider following scenario where we need to map one entity with other where one column of composite primary key of child table is by which we are mapping it with parent entity

Table 1: Employee_Details
Emp_Id (pk/id)
Emp_First_Name

Table 2: Emp_Skill_Level
Emp_Id (pk/id # 1)
Skill_Id (pk/id # 2)
Skill_Level

Now here we have a situation where in one table/entity we will have one column and Primary Key (or this will be my id field in mapped entity). The second table/entity has two columns as primary key and in mapped entity both these fields will be used to define id.

But we want to use only one column of Emp_Skill_Level to map with Employee_Details (For now lets assume we do not have any other table which lists details about Skill and all details are present in this second table)