2011-08-19 130 views
0

我有這樣的DB場景;許多複雜的休眠映射

基表:

STUDENT (student_id, name) 

SPORT (sport_id, name) 

SPORT_SUB (sport_sub_id, name) 

多對多映射表:

SPORT_CATEGORY (sport_id, sport_sub_id, sport_category_id) 

STUDENT_SPORT_CATEGORY (student_id, sport_category_id) 

任何人都可以提出一個方法使用Hibernate映射這一情況。我使用Hibernate工具和eclipse生成了POJO和HBM文件,並且它很成功。但是,當我試圖插入一個運動和運動子進入db後異常給出:

Foreign key (FK4979B7EDEB6823:student_sport_category [sport_category_id])) must have same number of columns as the referenced primary key (sport_category [sport_ID,sport_sub_ID]) 

任何建議將不勝感激。謝謝。 (厭倦了這個問題..)

+0

你可以發佈你的hbm文件和你用來插入Sport and Sport Sub的代碼嗎? – EkcenierK

回答

0

嗯,我不認爲你應該使用hibernate的許多2多映射。相反,創建一個聯結表(運動員左右,帶有student_id和sport_id)。 使用比2個一對多的關係。