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 |
From: Emmanuel B. (JIRA) <no...@at...> - 2006-05-29 14:28:19
|
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-352?pa= ge=3Dall ] =20 Emmanuel Bernard resolved ANN-352: ---------------------------------- Resolution: Rejected This is the correct behavior. According to the spec, you must specify the a= ssociation tables when using more than one association between 2 entities > 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 |
From: Max R. A. (JIRA) <no...@at...> - 2006-05-29 14:32:36
|
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-352?pag= e=3Dcomments#action_23191 ]=20 Max Rydahl Andersen commented on ANN-352: ----------------------------------------- since it does not make any sense shouldn't we complain about it via a Mappi= ngException or something ? > 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 |
From: Emmanuel B. (JIRA) <no...@at...> - 2006-05-29 14:40:22
|
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-352?pag= e=3Dcomments#action_23192 ]=20 Emmanuel Bernard commented on ANN-352: -------------------------------------- Well that's a tough one, we might want to complain if we use the default. B= ut what if the user did use the same assoc table explicitly for whatever re= ason. We shouldn't complain. > 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 |
From: Max R. A. (JIRA) <no...@at...> - 2006-05-29 16:40:39
|
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-352?pag= e=3Dcomments#action_23193 ]=20 Max Rydahl Andersen commented on ANN-352: ----------------------------------------- for some readonly crazy mapping ? what about only allowing that if they actually specified that ? meaning if = no table is specified and more than one manytomany for the same entity we c= omplain with a msg saying that you need to explicitly specify them.....but = maybe that is too much of a grey area handling. > 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 |
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 |