---
title: "Hibernate的一对多映射"
author: "cakin24"
date: "2017-11-09T21:42:56Z"
tags: []
categories: ["编程语言"]
slug: "hibernate"
draft: false
lastmod: "2017-11-09T21:42:56Z"
id: 2399232
url: "https://cakin24.iteye.com/blog/2399232"
---

一 映射类型分类

1 一对多(one-to-many)

2 多对一(many-to-one)

3 一对一(one-to-one)

4 多对多(many-to-many)

 

二 一对多映射介绍

1 生活举例

![](http://dl2.iteye.com/upload/attachment/0127/7451/ee9287f4-26db-371d-97ce-6d170b516dd5.png)  
 

2 具体方法

在数据库中，可以通过添加主外键的关联关系，表现出一对多的关系。

 

在Java代码中，通过一方持有多方的集合实现，即在“一”的一端中使用&lt;set&gt;元素表示持有“多”的一端的对象。