在完成了一对多的实例的基础上,继续做多对多实例。例子是老师和学生,一个老师教多个学生,一个学生也有多个老师。
文档结构如图:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAADdCAIAAAAdJ/jkAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAS/UlEQVR42u1da3AV5Rnmj//50Rn0R0dFnaY6SkXBMlL1j9fOlNapjnR0YLzVVh0JrRIECgahQVQolxAshIhcEiAxYoFw0SQ4BOgwQoJCAKdJCEhCEjwJybnlMNv3nMXDenb32+/7zu6ePbvPM+/s7H3P2X3Os+9+53v2HaFYYVvlagUAfIERbtK94PlSnHHA03S3EaA74Ct1b66emQ7QHfCzuh/bNvOnk0WgO5AHdK/df7yobIc+aL5+5ZXvLEpFSby7nCLcVtrbvLizcc6p7YU0k1aY9I8qBt1HpGA4brhODs7Rj0e35WPk8IsAxqeemM0/f9GsDxb865DSv984NCw3U3dDirvJEvbO7aU74EW6JxLDV65cDRpPJOKR8GWzn8H0wuVKz+fGoShb958kolOs29MMugNepHskMpSKQYpweLA/1HO+47QZ3V/482rl/AbT4MsWzLKajHUsE6GMEfZWcns2W4c9h3Fosy+LX5dLdB8a6h/xU7SdaVHprrbVaIdPTylX2koppry0duqLFOWpYTKm0PCl1JDGU0s51V3PAJ4Ria0sj6UfSo/IfS/AcboPDFwKhXr7+i709nx/sbuzs/3UmRNHzNT9iT9tVE4vUuPJ59Z/1nHFLP7w7Cc20l0vqJx71qssQ1wN6a7fj110R9aUA7qf6zj1XevR1uOHT7YcPNHc1HKk4eihvWZ0f/CPW5Rv51A8/HRl1Ylo1bfRqhOx5EhymI7ow09V8ufu/CrISMGzpKCZxruj7oB7dG85Ut/0Zc3+usrGus0UDbs2fbVnixndx/2uWml+c8Kk6vIDAxRrmwbKm5IjNFybGlJM+P029oOgYdrNk2HzbCKdVfOoO/9nNsvveR45AKfoLtTuTrjr8doxT3y2bEdvMnb2LNvRs2xnb2rYo84Z80St/08lx91GdD9gvBt0l0DBI58zIgh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a9U77KI7/3vigQCpe86rd2Sw0xYHBugOdTemuxeqdyhWvWFFXwMdBOsD6C6j7p6t3pEN3RVfd4sF3eXVPS+qd8i95B/qDnXPpHsOq3foU3N2DT2JhheoO9T9GvxUvQOAutsM2DuAPFZ3AIC6A4An8H/jAlKA+aui3gAAAABJRU5ErkJggg==" alt="" />
Student.java和Teacher.java的代码为:
package cn.hibernate.manytomany; import java.util.HashSet;
import java.util.Set; public class Student {
private int stuId;
private String stuName;
private Set<Teacher> teachers = new HashSet<Teacher>(); public Student(){ } public Student(int stuId, String stuName, Set<Teacher> teachers) {
this.stuId = stuId;
this.stuName = stuName;
this.teachers = teachers;
}
public int getStuId() {
return stuId;
}
public void setStuId(int stuId) {
this.stuId = stuId;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public Set<Teacher> getTeachers() {
return teachers;
}
public void setTeachers(Set<Teacher> teachers) {
this.teachers = teachers;
}
}
Student.java
package cn.hibernate.manytomany; import java.util.HashSet;
import java.util.Set; public class Teacher {
private int teaId;
private String teaName;
private Set<Student> stus = new HashSet<Student>();
public int getTeaId() {
return teaId;
}
public void setTeaId(int teaId) {
this.teaId = teaId;
}
public String getTeaName() {
return teaName;
}
public void setTeaName(String teaName) {
this.teaName = teaName;
}
public Set<Student> getStus() {
return stus;
}
public void setStus(Set<Student> stus) {
this.stus = stus;
}
public Teacher(int teaId, String teaName, Set<Student> stus) {
this.teaId = teaId;
this.teaName = teaName;
this.stus = stus;
} public Teacher(){ }
}
Teacher.java
在hibernate.cfg.xml最后添加映射关系:
<mapping resource="cn/hibernate/manytomany/teacher.hbm.xml"/>
<mapping resource="cn/hibernate/manytomany/student.hbm.xml"/>
teacher.hbm.xml和student.hbm.xml的代码为:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping>
<class name="cn.hibernate.manytomany.Teacher" table="t_teacher">
<id name="teaId" column="teaId">
<generator class="native"></generator>
</id> <property name="teaName" column="teaName" /> <!-- student不放弃外键的维护 -->
<set name="stus" table="t_tea_stu" cascade="all" inverse="false">
<key column="teaId"></key>
<many-to-many class="cn.hibernate.manytomany.Student" column="stuId"></many-to-many>
</set>
</class>
</hibernate-mapping>
teacher.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping>
<class name="cn.hibernate.manytomany.Student" table="t_student">
<id name="stuId" column="stuId">
<generator class="native"></generator>
</id> <property name="stuName" column="stuName"></property> <!-- teacher放弃外键的维护 -->
<set name="teachers" table="t_tea_stu" cascade="all" inverse="true">
<key column="stuId"></key>
<many-to-many class="cn.hibernate.manytomany.Teacher" column="teaId"></many-to-many>
</set>
</class>
</hibernate-mapping>
student.hbm.xml
MainFunc.java的代码为:
package cn.hibernate.manytomany; import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; public class MainFunc { public static void main(String[] args) {
// TODO Auto-generated method stub
Configuration cfg = new Configuration().configure();
SessionFactory sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = null;
try{
tx = session.beginTransaction(); Teacher tea1 = new Teacher();
tea1.setTeaName("Zhangsan");
Teacher tea2 = new Teacher();
tea2.setTeaName("Lisi"); Student stu1 = new Student();
stu1.setStuName("Sheldon");
Student stu2 = new Student();
stu2.setStuName("Leonard");
Student stu3 = new Student();
stu3.setStuName("Howard");
Student stu4 = new Student();
stu4.setStuName("Raj"); //把student和teacher关联
stu1.getTeachers().add(tea1);
stu1.getTeachers().add(tea2);
stu2.getTeachers().add(tea1);
stu2.getTeachers().add(tea2);
stu3.getTeachers().add(tea1);
stu4.getTeachers().add(tea2); //把teacher和student关联
tea1.getStus().add(stu1);
tea1.getStus().add(stu2);
tea1.getStus().add(stu3);
tea2.getStus().add(stu1);
tea2.getStus().add(stu2);
tea2.getStus().add(stu4); //由于teacher放弃了外键的维护,所以没有session.save(tea1/tea2)
session.save(stu1);
session.save(stu2);
session.save(stu3);
session.save(stu4); System.out.println("Add success");
tx.commit();
}catch(Exception e){
e.printStackTrace();
tx.rollback();
}finally{
session.close();
sessionFactory.close();
}
} }
MainFunc.java
最后,数据库中增加了t_teacher,t_student和中间表t_tea_stu
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIoAAAAwCAIAAABBtHUgAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACo0lEQVR42u2bvUvDQBjG8y917Co4KLj4LzhJJxEHERcpTsVJHCQ4FOoQqEOhHYR2KbSDELc4CHFweAeHjBkczqsfUE3uK6bJNXlejnAtyeVyvzy5j4dzGMLicNAEtcPTuYs63ndqd6PDm6h1RXsXtHtO26e0cUTNI0LTl4mnN2XuhLn37HLEOgPW9tjJLTvsxq3ruHUVNw8CNH0+eNpnbVFSqueES+c6+tLNxvFCNM2DRWrs+4pqfcZyxrqGK6RiWniM/ufRG6W0fvzOophRxMI31txp6Tz/n0yGFlzpVablZ6iPGZ7lGyjxzB7Cr8Tz43k4nAb9ScDxDCc+8JSPRySd/kiBx/mJ1J+a35bUq0TniO4l+sYmC08tRH5Jnnic36GpnjFP85Cz4brp3we9gR+8xvwowZMUjU4m29uaekLyPcglY6l6lnXD2fjPsXtnC55UFWbDk5SdxXgGsz/9DVcMp+J6/gKPN7MHj7IRs1WjHDyaIzfXG/MjEYWvFLyQ/0SzRxo/0HBO/SnJ8SRfRp2+R/Tk8s99aich6WnkckmtsKSLKm3ec9kdNjb3GlvCpDNyQ9Rozc1JBPAggAd4EMCDKAoP/B7b8cDvKQgP/B7b8ZiuGqyR37M69rmUXHe/p754RNKx0O+Rl7w63yg3PJX0e1im9WnNGylLtkI99vs9ch0YCXFN8KyP3yNvU9NmNfK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zMWL0l+fHBOJhmT1Wx//dosnfMIqH5VZfMPdDHANxDLCcBstCGSmwfGJZLiMFlpXWSC1yP9EuC2WkwDJ8DPgYYBkss7E8cwFPhPFlruo44xiiuRKJjNRgzCTS+PKSciWMKiPv56so3lzJMuwyr8pg2VcL7LJsroQ3ip+Mj6Fsl+NlGf4y5n6IYyCOAZbPybLcGimwrLFGCiwrrZFa3n6iXRbKSIFl+BjwMcAyWGZmWe67+OzpkoR/60UojsG+bikkJhcpy9Lr/XSCOFGz3H2RhZBdlmaZXWX+dSXSLF+0Xfa8hAhrpFJaV6K2qCZ2H0OOZYnfGErSLov6y+wZz7RZxtwPcQzEMcAy1kidgWWskdJgGUkmrJGCjwEfAz4GWAbLjreu87Ks9uIh9rpEvr8sFMdQy5Ww15XY7xZp5koY6xKJLy8j7xc7y3LrSnQCknqmCb/zGXt8Wc7HUPOXlZa8RbgOW2+yoHU7o1sjJZGRSm+9H+Z+iGMgjgGWsUbqnCxjjZQGy0gyYY0UfAz4GPAxwDJYVnmPlOYaqct9j5RariTe90hJ5/2QK0HeT5Flnbyf5hqpi7PLEvH1JFmWzvspr5GK3S5L+xjik4WY31UpapeV10hF6i9j7oc4BuIYYBlrpM7JMtZIabCMJNP8dNSAyhU2pg0qQ2WojC18+wcl8vkpblA06AAAAABJRU5ErkJggg==" alt="" width="159" height="219" />
完成了Hibernate的多对多的级联映射。
Hibernate的多对多实例的更多相关文章
-
【SSH系列】Hibernate映射 -- 多对多关联映射
映射原理 在数据库学习阶段,我们知道,如果实体和实体之间的关系是多对多,那么我们就抽出来第三张表,第一张表和第二张表的主键作为第三表的联合主键,结合我们的hibernate,多对多关联,无论 ...
-
hibernate之多对多关系
hibernate的多对多hibernate可以直接映射多对多关联关系(看作两个一对多) 下面我们拿三张表来做实例 t_book_hb t_book_category_hb(桥接表) t_catego ...
-
hibernate中多对多关联
hibernate中多对多关联 “计应134(实验班) 凌豪” 在关系数据库中有一种常见的关系即多对多关系,例如课程和学生的关系,一个学生可以选择多门课程,同时一门课程也可以被多个学生选择, 因此课程 ...
-
Springmvc+Spring+Hibernate搭建方法及实例
Springmvc+Spring+Hibernate搭建方法及实例
-
Hibernate 单项多对一的关联映射
在日常开发中会出现很对多对一的情况,本文介绍hibernate中多对一的关联映射. 1.设计表结构 2.创建student对象 3.创建Grade对象 4.写hbm.xml文件 5.生成数据库表 生成 ...
-
Hibernate的多对多映射关系
example: 老师(teacher)和学生(Student)就是一个多对多的关系吧?老师可以有多个学生,学生也可以由多个老师,那在Hibernate中多对多是怎样实现的呢?? 在Hibernate ...
-
Hibernate中多对多的annotation的写法(中间表可以有多个字段)
2011-07-04 6:52 一般情况下,多对多的关联关系是需要中间表的: 情况一:如果中间表仅仅是做关联用的,它里面仅有2个外键做联合主键,则使用ManyToMany(不用写中间表的Model,只 ...
-
hibernate关联关系 (多对多)
hibernate的多对多 hibernate可以直接映射多对多关联关系(看作两个一对多 多对多关系注意事项 一定要定义一个主控方 多对多删除 主控方直接删除 被控方先通过主控方解除多对多关系,再删 ...
-
Hibernate之多对多表,操作实例
多表操作之多对多关系简介 思路就是: 在数据库底层通过添加中间表来指定关联关系. 在双方的实体中添加一个保存对方的集合 在双方的配置文件中使用set标签和many-to-many标签来进行关联关系的配 ...
随机推荐
-
centos7中没有安装ifconfig命令的解决方法
初装centos 7时,运行config报 command not found 错误,我在网上找了大量资料,下面的资料中查找原因和解决方式最详细,能很好的解决这个问题. ifconfig命令是设置或显 ...
-
ebay api接口开发基本步骤
因公司项目需求,要进行ebay api开发,网上很多资料已过时,自己记录一下. 准备工作 一.注册账号 1开发者账号注册 https://developer.ebay.com/signin?retur ...
-
MySQL mac 安装
MySQL mac的安装着实费了些功夫.最开始想省事用brew 安装,结果总是有问题,原来brew安装MySQL并没那么简单,还要进行一些配置.索性直接到网站下载: http://www.mysql. ...
-
终极事务处理(XTP,Hekaton)——万能大招?
在SQL Server 2014里,微软引入了终极事务处理(Extreme Transaction Processing),即大家熟知的Hekaton.我在网上围观了一些文档,写这篇文章,希望可以让大 ...
-
SQL Server里如何随机记录集
今天的文章,我想给你简单介绍下SQL Server里如何随机记录集. SELECT * FROM Person.Person ORDER BY NEWID() GO 这会引入新的UNIQUEIDENT ...
-
PHP 设计模式 笔记与总结(6)基础设计模式:工厂模式、单例模式和注册树模式
三种基础设计模式(所有面向对象设计模式中最常见的三种): ① 工厂模式:使用工厂方法或者类生成对象,而不是在代码中直接new 在 Common 目录下新建 Factory.php: <?php ...
-
js遍历集合
首先,描述一下问题.由于需要后台取出数据,遍历展示在table中,大体如下: 后台取出的是 Map<String , List<Object>>,下面是我写得比较朴素一点的写法 ...
-
DB2存储过程实现查询表数据,生成动态SQL,并执行
一.动态执行SQL PREPARE S1 FROM 'delete from test'; EXECUTE S1; 二.使用游标 DECLARE V_CURSOR CURSOR FOR SELECT ...
-
玩转nodeJS系列:使用原生API实现简单灵活高效的路由功能(支持nodeJs单机集群),nodeJS本就应该这样轻快
前言: 使用nodeJS原生API实现快速灵活路由,方便与其他库/框架进行整合: 1.原生API,简洁高效的轻度封装,加速路由解析,nodeJS本就应该这样轻快 2.不包含任何第三方库/框架,可以灵活 ...
-
PowerEdge R430 机架式服务器安装( Ubuntu server 14.04.1 、PHP5.5.9、PHP-redis2.8、Phalcon3.1)
未解决问题:换成静态路由的话,怎么就 apt-get udpate 出现错误信息! 解决办法:么有设置网关 一.Ubuntu 系统下载地址: https://certification.ubuntu. ...