2022年hibernate多表查询 .pdf
《2022年hibernate多表查询 .pdf》由会员分享,可在线阅读,更多相关《2022年hibernate多表查询 .pdf(19页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、.多表查询:三个以上的表之间的关联;2.配置:分别配置两表之间的关联映射;3.查询:from a join b join c.join z hibernate.cfg.xml:view sourceprint?01.02.05.06.07.08.09.10.scott 11.12.jdbc:oracle:thin:127.0.0.1:1521:MGC 13.14.15.org.hibernate.dialect.Oracle9Dialect 名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 19 页 -16.17.MGC 18.tiger 19.20.oracle.jdbc.dri
2、ver.OracleDriver 21.22.23.true 24.25.26.27.28.Student.java:view sourceprint?01.package cn.edu.ahau.mgc.hibernate.pojo;02.03.publicclass Student 04.05.privatelong id;06.privateString name;07.privateClasses classes;名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 19 页 -08.09.publicClasses getClasses()10.returnclasses;1
3、1.12.13.publicvoid setClasses(Classes classes)14.this.classes=classes;15.16.17.publiclong getId()18.returnid;19.20.21.publicvoid setId(longid)22.this.id=id;23.24.25.publicString getName()26.returnname;27.28.29.publicvoid setName(String name)30.this.name=name;31.32.Classes.java:view source名师资料总结-精品资料
4、欢迎下载-名师精心整理-第 3 页,共 19 页 -print?01.package cn.edu.ahau.mgc.hibernate.pojo;02.03.importjava.util.Set;04.05.publicclass Classes 06.07.privatelong id;08.privateString name;09.privateSet students;10.11.publiclong getId()12.returnid;13.14.15.publicvoid setId(longid)16.this.id=id;17.18.19.publicString get
5、Name()20.returnname;21.22.23.publicvoid setName(String name)24.this.name=name;25.名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 19 页 -26.27.publicSet getStudents()28.returnstudents;29.30.31.publicvoid setStudents(Set students)32.this.students=students;33.34.Course.java:view sourceprint?01.package cn.edu.ahau.mgc.hi
6、bernate.pojo;02.03.publicclass Course 04.05.privatelong id;06.privateString name;07.08.publiclong getId()09.returnid;10.11.12.publicvoid setId(longid)名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 19 页 -13.this.id=id;14.15.16.publicString getName()17.returnname;18.19.20.publicvoid setName(String name)21.this.name=n
7、ame;22.23.Grade.java:view sourceprint?01.package cn.edu.ahau.mgc.hibernate.pojo;02.03.publicclass Grade 04.05.privatelong id;06.privateStudent student;07.privateCourse course;08.privateint grade;09.10.publiclong getId()名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 19 页 -11.returnid;12.13.14.publicvoid setId(longid
8、)15.this.id=id;16.17.18.publicStudent getStudent()19.returnstudent;20.21.22.publicvoid setStudent(Student student)23.this.student=student;24.25.26.publicCourse getCourse()27.returncourse;28.29.30.publicvoid setCourse(Course course)31.this.course=course;32.33.34.publicint getGrade()35.returngrade;36.
9、37.38.publicvoid setGrade(intgrade)39.this.grade=grade;名师资料总结-精品资料欢迎下载-名师精心整理-第 7 页,共 19 页 -40.41.Join.hbm.xml:view sourceprint?01.02.04.07.08.09.10.11.12.13.14.15.16.17.名师资料总结-精品资料欢迎下载-名师精心整理-第 8 页,共 19 页 -18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.名师资料总结-精品资料欢迎下载-名师
10、精心整理-第 9 页,共 19 页 -43.44.45.46.47.48.49.50.51.52.53.54.55.HibernateSessionFactory.java:view sourceprint?001.package cn.edu.ahau.mgc.hibernate.many2one.factory;002.003.importorg.hibernate.HibernateException;004.importorg.hibernate.Session;005.importorg.hibernate.cfg.Configuration;006.名师资料总结-精品资料欢迎下载-
11、名师精心整理-第 10 页,共 19 页 -007./*008.*Configures and provides access to Hibernate sessions,tied to the 009.*current thread of execution.Follows the Thread Local Session 010.*pattern,see link http:/hibernate.org/42.html;.011.*/012.publicclass HibernateSessionFactory 013.014./*015.*Location of hibernate.cf
12、g.xml file.016.*Location should be on the classpath as Hibernate uses 017.*#resourceAsStream style lookup for its configuration file.018.*The default classpath location of the hibernate config file is 019.*in the default package.Use#setConfigFile()to update 020.*the location of the configuration fil
13、e for the current session.021.*/022.privatestaticString CONFIG_FILE_LOCATION=/hibernate.cfg.xml;023.privatestaticfinalThreadLocal threadLocal=newThreadLocal();024.privatestaticConfiguration configuration=newConfiguration();025.privatestaticorg.hibernate.SessionFactory sessionFactory;026.privatestati
14、cString configFile=CONFIG_FILE_LOCATION;027.028.static 029.try 名师资料总结-精品资料欢迎下载-名师精心整理-第 11 页,共 19 页 -030.configuration.configure(configFile);031.sessionFactory=configuration.buildSessionFactory();032.catch(Exception e)033.System.err 034.println(%Error Creating SessionFactory%);035.e.printStackTrace(
15、);036.037.038.privateHibernateSessionFactory()039.040.041./*042.*Returns the ThreadLocal Session instance.Lazy initialize 043.*the SessionFactory if needed.044.*045.*return Session 046.*throws HibernateException 047.*/048.publicstaticSession getSession()throwsHibernateException 049.Session session=(
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年hibernate多表查询 2022 hibernate 查询
限制150内