Entity class
1 public class Student {2 private int id;3 private String name;4 Private set<score> Scores = new hashset<score> (); One-to-many 5}
1 public class score {2 private int id;3 private Student Student; 1 pair of private Course Course; 1 pair of private Double score;6}
1 public class Course {2 private int id;3 private String name;4 Private set<score> Scores = new hashset<score> (); One-to-many 5}
Mode one mapping relationship (many-to-one) with 3 configuration files
1 Package= "Entity" >2<className= "Course" >3<id name= "id" >4<generatorclass= "Native"/>5</id>6<property name= "Name"/>7<set name= "scores" inverse= "true" >8<key column= "CourseID"/>9<one-to-manyclass= "Score"/>Ten</set> One</class> A1 Package= "Entity" >2<className= "Score" >3<id name= "id" >4<generatorclass= "Native"/>5</id>6<property name= "Score"/>7<many-to-one name= "Student" column= "StudentID" not-NULL= "true"/>8<many-to-one name= "Course" column= "CourseID" not-NULL= "true" lazy= "false"/>9</class>Ten1 Package= "Entity" >2<className= "Student" >3<id name= "id" >4<generatorclass= "Native"/>5</id>6<property name= "Name"/>7 8<set name= "scores" inverse= "true" lazy= "false" >9<key column= "StudentID"/>Ten<one-to-manyclass= "Score"/> One</set> A</class> -Mode two configuration (only two files)
1 Package= "Entity" >2<className= "Student" >3<id name= "id" >4<generatorclass= "Native"/>5</id>6<property name= "Name"/>7<set name= "scores" lazy= "true" table= "Score" >8<key column= "StudentID"/>9<!--composition element mapping--Ten<composite-elementclass= "Score" > One<!--a property name that references the current entity class in the score class-- A<parent name= "Student"/> -<property name= "Score"/> -<!--Many-to-one association between the score class and the course class- the<many-to-one name= "Course"class= "Course" column= "CourseID"/> -</composite-element> -</set> -</class> +1 Package= "Entity" >2<className= "Course" >3<id name= "id" >4<generatorclass= "Native"/>5</id>6<property name= "Name"/>7<set name= "scores" lazy= "true" table= "Score" inverse= "true" >8<key column= "CourseID"/>9<composite-elementclass= "Score" >Ten<parent name= "Course"/> One<property name= "Score"/> A<many-to-one name= "Student"class= "Student" column= "StudentID" foreign-key= "StudentID"/> -</composite-element> -</set> the</class> -Hibernate mapping (student-subject-score)