1-7 hibernate关联关系映射

时间:2023-03-09 22:38:26
1-7 hibernate关联关系映射

1.关联关系分为单向关联(一对一,一对多,多对一,多对多),多向关联(一对一,一对多,多对多)。

2.单向一对一主键关联实例

1-7 hibernate关联关系映射

1-7 hibernate关联关系映射

需要为one-to-one元素指定constrained属性值为true.

3.单向一对一外键关联

1-7 hibernate关联关系映射

4.一对多关联

建立一对多关联时,需要在“一"端的映射文件中使用one-to-many元素来映射关联的实体类,

class指定关联类的名称,

not-found该属性值为exception和ignore

1-7 hibernate关联关系映射

5.单多对一

通过外键来关联,需要用many-to-one标签,属性如下

1-7 hibernate关联关系映射

1-7 hibernate关联关系映射