From: Emmanuel B. (JIRA) <no...@at...> - 2006-05-29 16:50:27
|
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-352?pag= e=3Dcomments#action_23194 ]=20 Emmanuel Bernard commented on ANN-352: -------------------------------------- The problem is that implementing something like that is not trivial and wil= l ovscure the code even more. Not sure it worth it. > Incorrect database sceme created, when using multiple n:m relations betwe= en 2 entities > -------------------------------------------------------------------------= ------------- > > Key: ANN-352 > URL: http://opensource.atlassian.com/projects/hibernate/browse/A= NN-352 > Project: Hibernate Annotations > Type: Bug > Versions: 3.2.0.cr1 > 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= =3DCascadeType.PERSIST) > protected Set<UserBean> getAdminUsers() { > @ManyToMany(mappedBy=3D"lectures", fetch=3DFetchType.LAZY, cascade=3DCasc= adeType.PERSIST) > protected Set<UserBean> getUsers() { > .... > } > so there are 2 n:m relations between these entities. Hibernate generates = the following table: > adminusers_userid | adminlectures_lectureid | users_userid | lectures_lec= tureid > so it puts these 2 relations in one table but it adds foreign keys: > =C2=BBfk3fb6262a62053223=C2=AB FOREIGN KEY (adminlectures_lectureid) = REFERENCES lecturebean(lectureid) > =C2=BBfk3fb6262a569b3581=C2=AB FOREIGN KEY (users_userid) REFERENCES = userbean(userid) > =C2=BBfk3fb6262afb45c494=C2=AB FOREIGN KEY (lectures_lectureid) REFER= ENCES lecturebean(lectureid) > =C2=BBfk3fb6262a66a3ba50=C2=AB FOREIGN KEY (adminusers_userid) REFERE= NCES 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 ar= ound 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 |