From: Erik T. (JIRA) <no...@at...> - 2006-05-29 12:31:23
|
Incorrect database sceme created, when using multiple n:m relations between= 2 entities ---------------------------------------------------------------------------= ----------- Key: ANN-352 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN= -352 Project: Hibernate Annotations Type: Bug Versions: 3.2.0.cr1 =20 Environment: Linux, Java 1.5, Postgresql 8.0 Reporter: Erik Tews Hi I got 2 entities: @Entity public class UserBean implements Serializable { .... @ManyToMany protected Set<LectureBean> getAdminLectures() { .... @ManyToMany protected Set<LectureBean> getLectures() { .... } and on the other side @Entity=20 public class LectureBean implements Serializable { @ManyToMany(mappedBy=3D"adminLectures", fetch=3DFetchType.LAZY, cascade=3DC= ascadeType.PERSIST) protected Set<UserBean> getAdminUsers() { @ManyToMany(mappedBy=3D"lectures", fetch=3DFetchType.LAZY, cascade=3DCascad= eType.PERSIST) protected Set<UserBean> getUsers() { .... } so there are 2 n:m relations between these entities. Hibernate generates th= e following table: adminusers_userid | adminlectures_lectureid | users_userid | lectures_lectu= reid so it puts these 2 relations in one table but it adds foreign keys: =C2=BBfk3fb6262a62053223=C2=AB FOREIGN KEY (adminlectures_lectureid) RE= FERENCES lecturebean(lectureid) =C2=BBfk3fb6262a569b3581=C2=AB FOREIGN KEY (users_userid) REFERENCES us= erbean(userid) =C2=BBfk3fb6262afb45c494=C2=AB FOREIGN KEY (lectures_lectureid) REFEREN= CES lecturebean(lectureid) =C2=BBfk3fb6262a66a3ba50=C2=AB FOREIGN KEY (adminusers_userid) REFERENC= ES userbean(userid) This makes it impossible to put 2 entities in relation, because 2 of the 4 = columns will always be null. Adding differen column names for the join tables with @JoinTable works arou= nd the problem. --=20 This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators= .jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |