Hibernate多对一关系映射
来源:互联网 发布:贵金属模拟软件 编辑:程序博客网 时间:2024/05/27 18:17
12720171106
package com.tiger.main;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuration;import com.tiger.bean.School;import com.tiger.bean.Student;/** * n - 1(many to one) * 多位学生属于共同的一所大学(many 指的是学生) * 一所大学包含多位学生(one 指的是学校) * @author tiger * @date 2017年11月6日 */public class Main_many_one {public static void main(String[] args) {Configuration cfg = new Configuration().configure("hibernate.cfg.xml");SessionFactory sf = cfg.buildSessionFactory();Session session = sf.openSession();Transaction tx = session.beginTransaction();//new 一座大学School school01 = new School();school01.setName("北理工");School school02 = new School();school02.setName("北师珠");//new 多位学生Student student01 = new Student();student01.setName("小明");student01.setSchool(school01);Student student02 = new Student();student02.setName("小红");student02.setSchool(school01);Student student03 = new Student();student03.setName("小黄");student03.setSchool(school02);Student student04 = new Student();student04.setName("小黑");student04.setSchool(school02);session.save(student01);session.save(student02);session.save(student03);session.save(student04);tx.commit();session.close();sf.close();}}package com.tiger.bean;/** * n 学生有很多 * @author tiger * @date 2017年11月6日 */public class Student {private Integer id;private String name;private School school;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public School getSchool() {return school;}public void setSchool(School school) {this.school = school;}public Student() { }@Overridepublic String toString() {return "Student [id=" + id + ", name=" + name + ", school=" + school + "]";}} package com.tiger.bean;/** * 1 * 一所学生被多位学生共享 * @author tiger * @date 2017年11月6日 */public class School {private Integer id;private String name;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public School() {super();}@Overridepublic String toString() {return "School [id=" + id + ", name=" + name + "]";}} org.hibernate.dialect.MySQL5InnoDBDialect com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/book_many_one root 123456 30 10 5000 create true
阅读全文
1 0
- hibernate 多对一关系映射
- hibernate多对一关系映射
- hibernate双向多对一映射关系
- Java- Hibernate 多对一关系映射
- hibernate中多对一关系映射
- Hibernate关系映射多对一
- Hibernate多对一关系映射
- Hibernate关联关系映射-----单向多对一映射配置
- Hibernate关联关系映射(多对一关联映射)
- Hibernate多对多关系映射拆解为两队多对一关系映射
- Hibernate之关联关系映射(一对多和多对一映射,多对多映射)
- Hibernate关联关系映射 一对一 一对多 多对一
- Hibernate的关系映射-------多对一与一对多
- hibernate的一对多和多对一关系映射
- Hibernate 关系映射--多对一、一对多总结篇
- hibernate 映射关系 一对多/多对一
- Hibernate关联关系映射(一对多/多对一)
- hibernate映射关系 一对多&多对一
- 每次开机无线网卡启动慢,无法连接无线网络,等一段时间恢复正常
- Python中的yield
- Java8 Date总结
- 如何通过adb shell 循环读取寄存器状态
- Python高级编程-如何快速找到多个字典中的公工键(key)
- Hibernate多对一关系映射
- ubuntu16.04 failed to install sougoupingying
- ===注册时使用消息队列 发送邮件。遇到的【环境问题】总结。==比代码问题难找!!!
- MySQL 线上删1T大表记录
- JQuery DataTables显示行号及连续自动编号
- 动态规划--最大子矩阵和
- Imageloader基本使用
- 数据结构实验之二叉树八:(中序后序)求二叉树的深度
- Count the Tetris HDU