如果People1定义了mappedBy,则在work表生成到People1的外键,work是这个关系的拥有者;
如果work定义了mappedBy,则在People1表生成到work的外键,People1是这个关系的拥有者。
在双向关联中,有且仅有一段是作为主体(owner)端在的:
主体端负责维护联接(即更新),对于不需要维护这种关系得从表则通过mappedBy进行声明。
OneToOne
There are three cases for one-to-one associations:
1. either the associated entities share the same primary keys values,
2. a foreign key is held by one of the entities (note that this FK column in the database should be constrained unique to simulate one-to-one multiplicity),
3. a association table is used to store the link between the 2 entities (a unique constraint has to be defined on each fk to ensure the one to one multiplicity)
the first:share the same primary keys values
- @Entity
- public class People1 implements java.io.Serializable {
-
- private Integer id;
-
- private String name;
-
- private Work work;
-
- @Id
- public Integer getId() {
- return id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @OneToOne(cascade = CascadeType.ALL)
- @PrimaryKeyJoinColumn
- public Work getWork() {
- return work;
- }
-
- public void setWork(Work work) {
- this.work = work;
- }
-
- @Entity
- public class Work implements java.io.Serializable {
-
- private int id;
-
- private String corpname;
-
- private People1 people1;
-
- @OneToOne(mappedBy = "work")
- public People1 getPeople1() {
- return this.people1;
- }
-
- public void setPeople1(People1 people1) {
- this.people1 = people1;
- }
-
- public String getCorpname() {
- return corpname;
- }
-
- public void setCorpname(String corpname) {
- this.corpname = corpname;
- }
-
- @Id
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
分享到:
相关推荐
现在已经不用*.hbm.xml这种映射文件了,都是用Annotation(注解)方式来完成实体与表之间的映射关系,这样看起来比用xml文件来映射更具有可读性,自我感觉以后Hibernate Annotation的映射方式将代替hibernate 的*....
Hibernate Annotations API 中文文档 前言 1. 创建一个注解项目 1.1. 系统需求 1.2. 系统配置 2. 实体Bean 2.1. 简介 2.2. 用EJB3注解进行映射 2.2.1. 声明实体bean 2.2.1.1. 定义表(Table) 2.2.1.2. 乐观...
hibernate-annotations-3.4.0.GA hibernate-annotations-3.4.0.GA hibernate-annotations-3.4.0.GA
hibernate annotations 中文参考手册
Hibernate Annotations 中文版
webwork2.1.7 中文开发文档 Hibernate Annotations参考文档-3.20中文开发文档 Hibernate_3.2.0_Reference_zh_CN中文开发文档
hibernate annotations 3.4.0.GA API
hibernate 和hibernate_annotations(中文API)帮助文档。
hibernate annotations
hibernate annotations 的中文帮助文档 可以帮您更好的学习hibernate 的注解配置
Hibernate3.2 Annotations中文文档 Hibernate3.2 Annotations中文文档 Hibernate3.2 Annotations中文文档 网页格式
NULL 博文链接:https://xiongjiajia.iteye.com/blog/1947270
Hibernate Annotations API英文版,CHM格式
hibernate annotations 核心包,欢迎下载
hibernate-annotations-3.4.0
hibernate-annotations.jar
使用注解Annotation时用的jar包。 包括: hibernate-commons-annotations-3.3.0.ga.jar hibernate-entitymanager.jar ejb3-persistence.jar hibernate-annotations.jar
hibernate-annotations-3.4.0.CR1中文电子书
解压后可得hibernate-annotations.jar和hibernate-annotations-src.zip,hibernate-annotations-src.zip为hibernate-annotations.jar的源代码