我正在使用XML映射在hibernate中进行简单的多对多映射。在这个项目中我收到以下错误:
Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity: org.many_to_many.model.Course column: Course_ID (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:764)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:782)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:804)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:539)
at org.hibernate.mapping.RootClass.validate(RootClass.java:265)
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:464)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.many_to_many.client.TestClass.main(TestClass.java:16)
学生班:
private int student_ID;
private String student_Name;
private Set<Course> courses;
//getter,setter and constructor
课程类:
private int course_ID;
private String course_Name;
private Set<Student> students;
//getter,setter and constructor
student.hbm.xml:
<class name = "org.many_to_many.model.Student" table = "STUDENT">
<id name = "student_ID" column = "Student_ID">
<generator class = "native"></generator>
</id>
<property name = "student_Name" column = "Student_Name"></property>
<set name = "course" table = "student_course" inverse = "true">
<key column = "Student_ID"/>
<many-to-many column = "Course_ID" class = "org.many_to_many.model.Course"/>
</set>
</class>
course.hbm.xml:
<class name = "org.many_to_many.model.Course" table = "COURSE">
<id name = "course_ID" column = "Course_ID">
<generator class = "native"></generator>
</id>
<property name = "course_Name" column = "Course_ID"></property>
<set name = "students" table = "student_course" cascade = "all" inverse = "true">
<key column = "Course_ID"/>
<many-to-many class = "org.many_to_many.model.Student" column = "Student_ID"></many-to-many>
</set>
</class>
任何人都可以告诉我我的错误是什么,或者可以通过对多对多映射的一些解释来解决这个问题。谢谢。
答案 0 :(得分:0)
在course.hbm.xml中,您有<property name = "course_Name" column = "Course_ID"></property>