Chapter 10 annotation-based relationship ing

Source: Internet
Author: User

If the following content does not understand, you can find it:

Annotation-based relationship ing preparations: Http://blog.csdn.net/p_3er/article/details/9061911

XML-Based Multi-to-many: http://blog.csdn.net/p_3er/article/details/9053415

 

Student:
@ Entity @ table (name = "student", catalog = "hibernate") public class student implements Java. io. serializable {private integer ID; private string sname; private set <teacher> teachers; Public student () {}@ ID @ generatedvalue @ column (name = "ID", unique = true, nullable = false) Public integer GETID () {return this. ID;} public void setid (integer ID) {This. id = ID ;}@ column (name = "s_name", nullable = false, length = 45) Public String getsname () {return this. sname;} public void setsname (string sname) {This. sname = sname;} @ manytomany (cascade = cascadetype. all, targetentity = cn. framelife. hibernate. entity. teacher. class) @ jointable (name = "S_T", catalog = "hibernate", joincolumns ={@ joincolumn (name = "student_id ")}, inversejoincolumns ={@ joincolumn (name = "teacher_id")})/* ing file comparison: <set name = "Teachers" table = "S_T" cascade = "all"> <key column = "student_id"/> <your-to-convert column = "teacher_id" class = "CN. framelife. hibernate. entity. teacher "> </register-to-register> </set> */Public set <teacher> getteachers () {return teachers;} public void setteachers (set <teacher> teachers) {This. teachers = teachers ;}}

 

TEACHER:
@ Entity @ table (name = "teacher", catalog = "hibernate") public class teacher implements Java. io. serializable {private integer ID; private string tname; private set <student> students; public teacher () {}@ ID @ generatedvalue @ column (name = "ID", unique = true, nullable = false) Public integer GETID () {return this. ID;} public void setid (integer ID) {This. id = ID ;}@ column (name = "t_name", nullable = false, length = 45) Public String gettname () {return this. tname;} public void settname (string tname) {This. tname = tname;} @ manytomany (cascade = cascadetype. all, targetentity = cn. framelife. hibernate. entity. student. class) @ jointable (name = "S_T", catalog = "hibernate", joincolumns ={@ joincolumn (name = "teacher_id ")}, inversejoincolumns ={@ joincolumn (name = "student_id")}) Public set <student> getstudents () {return students;} public void setstudents (set <student> students) {This. students = students ;}}

 

 

 

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.