Hibernate关系映射123

多对一单向映射 –> hibernate=-4

1
2
3
4
 <many-to-onename="category"class="com.yuan.hibernate.Category"fetch="join">
<columnname="CATEGORYID"/>
</many-to-one>
privateCategorycategory;

多对一双向映射 –> hibernate-5

1
2
3
<many-to-onename="category"class="com.yuan.hibernate.Category"fetch="join">
<columnname="CATEGORY"/>
</many-to-one>

1
2
3
4
5
6
7
  <setname="book"table="BOOK"inverse="false"lazy="true">
<key>
<columnname="ID"/>
</key>
<one-to-manyclass="com.yuan.hibernate.Book"/>
</set>
privateSet<Book>book;

一对一主键关系映射 –> hibernate-6

1
2
3
4
<one-to-onename="user"class="com.yuan.model.User"></one-to-one>
<one-to-onename="idCard"class="com.yuan.model.IdCard"></one-to-one>
privateUseruser;
privateIdCardidCard;

一对一主键外键关系映射 – > hibernate-7

1
2
<many-to-onename="idCard"update="true"/>
privateIdCardidCard;

多对多关系映射 – > hibernate-8

1
2
3
4
5
6
7
<setname="students"table="STUDENT_COURSE"inverse="false"lazy="true">
<key>
<columnname="COURSEID"/>
</key>
<many-to-manyclass="com.yuan.model.Student"column="STUDENTID"/>
</set>
```







privateSetstudents;
privateSetcourses;
```