2016-10-03 7 views
0

XMLマッピングを使用して、単純な多対多マッピングを行っています。このプロジェクトでは、次のエラーが発生します。org.hibernate.MappingException:エンティティ:org.many_to_many.model.Course列のマッピングの繰り返しの列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

oh i got it.Thank u very much – Rohit

関連する問題