---
title: "Hibernate foreign配置"
author: "freeglad"
date: "2008-10-27T15:54:00Z"
tags: []
slug: "hibernate-foreign"
draft: false
lastmod: "2008-10-27T15:54:00Z"
id: 586552
url: "https://freeglad.iteye.com/blog/586552"
---

**级联保存**  
1、一对多级联保存：在&lt;many-to-one&gt;和&lt;set&gt;都加上cascade="save-update"  
2、一对一级联保存则在&lt;one-to-one&gt;配置上加上cascade="save-update"

**foreign配置**  
被设为外键方：  
&lt;generator class="foreign"&gt;  
&lt;param name="property"&gt;users&lt;/param&gt;  
&lt;/generator&gt;  
&lt;one-to-one name="users" class="com.zjhk.shop.vo.Users" constrained="true" cascade="save-update" /&gt;

主键方：  
&lt;one-to-one name="shoppingCarts" class="com.zjhk.shop.vo.ShoppingCart" cascade="save-update"/&gt;