- 浏览: 70905 次
- 性别:
-
文章分类
最新评论
package com.bjsxt.hibernate; import java.util.HashSet; import java.util.Set; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.OneToMany; import javax.persistence.Table; @Entity public class Teacher { private int id; private String name; private Set<Student> students = new HashSet<Student>(); @Id @GeneratedValue public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @ManyToMany @JoinTable(name="t_s", 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; } }
package com.bjsxt.hibernate; import java.util.HashSet; import java.util.Set; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToMany; @Entity public class Student { private int id; private String name; private Set<Teacher> teachers = new HashSet<Teacher>(); @ManyToMany(mappedBy="students") public Set<Teacher> getTeachers() { return teachers; } public void setTeachers(Set<Teacher> teachers) { this.teachers = teachers; } @Id @GeneratedValue public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.bjsxt.hibernate.Teacher"> <id name="id"> <generator class="native"></generator> </id> <property name="name"></property> <set name="students" table="t_s"> <key column="teacher_id"></key> <many-to-many class="com.bjsxt.hibernate.Student" column="student_id"/> </set> </class> </hibernate-mapping>
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.bjsxt.hibernate.Student"> <id name="id"> <generator class="native"></generator> </id> <property name="name"></property> <set name="teachers" table="t_s"> <key column="student_id"></key> <many-to-many class="com.bjsxt.hibernate.Teacher" column="teacher_id"/> </set> </class> </hibernate-mapping>
发表评论
-
22.hibernate继承映射joined
2011-12-07 18:14 796person表结构: teacher表结构: studen ... -
21.hibernate继承映射table_per_class
2011-12-07 18:14 1099t_gen_table表结构: person表结构: te ... -
20.hibernate继承映射single_table
2011-11-25 12:17 936单个表: person表结构如下: package co ... -
18.hibernate多对多单向关联
2011-11-25 12:17 761package com.bjsxt.hibernate; ... -
17.hibernate一对多,多对一双向关联
2011-11-25 12:17 956package com.bjsxt.hibernate; ... -
16.hibernate一对多单向关联
2011-11-25 12:16 773package com.bjsxt.hibernate; ... -
15.hibernate多对一单向关联
2011-11-24 00:48 838package com.bjsxt.hibernate; ... -
14.hibernate 一对一component(组合),jpa映射
2011-11-24 00:48 1127只存在一个表: husband表结构: package ... -
13.hibernate一对一单向联合主键外键关联,jpa映射
2011-11-24 00:47 1596husband表结构: wife表结构: packag ... -
12.hibernate一对一双向主键关联,jpa映射
2011-11-24 00:47 1028husband表结构: wife表结构: pack ... -
11.hibernate一对一双向主键关联,xml映射
2011-11-24 00:46 830student表结构: stuidcard表结构 ... -
10.hibernate一对一单向主键关联,jpa映射
2011-11-23 19:43 1508husband表结构: wife表结构: pac ... -
9.hibernate一对一单向主键关联,xml映射
2011-11-23 19:42 971student表结构: stuidcard表结构 pa ... -
8.hibernate一对一双向外键关联,jpa映射
2011-11-23 19:42 904husband表结构: wife表结构 packa ... -
7.hibernate一对一双向外键关联,xml映射
2011-11-23 19:41 930stuidcard表结构: student表结构: ... -
6.hibernate一对一单向外键关联,jpa映射
2011-11-23 19:40 1713husband表结构: wife表结构 package ... -
5.hibernate一对一单向外键关联,xml映射
2011-11-21 18:25 471stuidcard表结构: student表结构: p ... -
4.hibernate联合主键,jpa映射
2011-11-21 18:17 977package com.bjsxt.hibernate; ... -
3.hibernate联合主键,xml映射
2011-11-21 18:13 1005package com.bjsxt.hibernate; ... -
2.hibernate 枚举类型, 布尔类型,不持久化属性映射
2011-11-21 18:06 1434package com.bjsxt.hibernate; ...
相关推荐
7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂...
7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂...
7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂...
7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂的...
7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂...
7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂...
8.5. 使用连接表的双向关联(Bidirectional associations with join tables) 8.5.1. 一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件...
8.5. 使用连接表的双向关联(Bidirectional associations with join tables) 8.5.1. 一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件...
使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂的...
7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 8. 组件...
8.5. 使用连接表的双向关联(Bidirectional associations with join tables) 8.5.1. 一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件...
使用连接表的双向关联(Bidirectional associations with join tables) 8.5.1. 一对多(one to many) /多对一( many to one) 8.5.2. 一对一(one to one) 8.5.3. 多对多(many to many) 9. 组件...
7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 7.6. 更复杂的...
7.5. 使用连接表的双向关联(Bidirectional associations with join tables) 7.5.1. 一对多(one to many) /多对一( many to one) 7.5.2. 一对一(one to one) 7.5.3. 多对多(many to many) 8. 组件...
双向关联(Bidirectional Associations) 6.9. 三重关联(Ternary Associations) 6.10. 异类关联(Heterogeneous Associations) 6.11. 集合例子(Collection example) 7. 组件(Component)映射 ...
双向关联(Bidirectional Associations) 6.9. 三重关联(Ternary Associations) 6.10. 异类关联(Heterogeneous Associations) 6.11. 集合例子(Collection example) 7. 组件(Component)映射 ...
7.2 映射一对多双向关联关系 7.2.1 元素的inverse属性 7.2.2 级联删除 7.2.3 父子关系 7.3 映射一对多双向自身关联关系 7.4 改进持久化类 7.5 小结 7.6 思考题 第8章 通过Hibernate操纵对象(上) ...
7.2 映射一对多双向关联关系 7.2.1 元素的inverse属性 7.2.2 级联删除 7.2.3 父子关系 7.3 映射一对多双向自身关联关系 7.4 改进持久化类 7.5 小结 7.6 思考题 第8章 通过Hibernate操纵对象(上) ...