Hibernate mapping (student-subject-score)

Source: Internet
Author: User

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> A
1 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>Ten
1 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.