2016-10-03 208 views
0

我正在做一個簡單的多對多映射,在使用XML映射的hibernate中。在這個項目中,我得到以下錯誤:org.hibernate.MappingException:爲實體映射中的重複列:org.many_to_many.model.Course column Course_ID

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) 

Student類:

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

在course.hbm.xml中你有<property name = "course_Name" column = "Course_ID"></property>

+0

哦,我明白了。非常感謝你 – Rohit

相關問題