开发者

Many to many complex hibernate mapping

开发者 https://www.devze.com 2023-03-29 09:25 出处:网络
I have a DB scenario like this; Base tables: STUDENT (student_id, name) SPORT (sport_id, name) SPORT_SUB (sport_sub_id, name)

I have a DB scenario like this;

Base tables:

STUDENT (student_id, name)

SPORT (sport_id, name)

SPORT_SUB (sport_sub_id, name)

Many to many mapping tables:

SPORT_CATEGORY (s开发者_如何学运维port_id, sport_sub_id, sport_category_id) 

STUDENT_SPORT_CATEGORY (student_id, sport_category_id)

Can anyone suggest a way to map this scenario using hibernate. I generated POJOs and hbm files using Hibernate tools with eclipse and it was successful. But when I tried to insert a Sport and Sport Sub into the db following exception is given:

    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])

Any suggestion will be highly appreciated. thanks. (fed up with this issue..)


Well I don't think that you should use hibernate's many-2-many mapping. Instead create a junction tables (sporters or so, with a student_id and an sport_id). Use than 2 one-to-many relationships.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号