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 ;}}