Bidirectional OneToOne Relationships

Assuming that:
                          Entity A references a single instance of Entity B.
                          Entity B references a single instance of Entity A.
                          Entity A is specified as the owner of the relationship.
          The following mapping defaults apply:
                          Entity A is mapped to a table named A.
                          Entity B is mapped to a table named B.
          Table A contains a foreign key to table B. The foreign key column name is formed as the concatenation
           of the following: the name of the relationship property or field of entity A; "_"; the
           name of the primary key column in table B. The foreign key column has the same type as the
           primary key of table B and there is a unique key constraint on it.
Example:
@Entity
public class Employee {
       private Cubicle assignedCubicle;
       @OneToOne
       public Cubicle getAssignedCubicle() {
             return assignedCubicle;
       }
       public void setAssignedCubicle(Cubicle cubicle) {
            this.assignedCubicle = cubicle;
       }
       ...
}
               

@Entity
public class Cubicle {
        private Employee residentEmployee;
        @OneToOne(mappedBy="assignedCubicle")
        public Employee getResidentEmployee() {
              return residentEmployee;
        }
        public void setResidentEmployee(Employee employee) {
              this.residentEmployee = employee;
        }
        ...
}

In this example:
                           Entity Employee references a single instance of Entity Cubicle.
                           Entity Cubicle references a single instance of Entity Employee.
                           Entity Employee is the owner of the relationship.
            The following mapping defaults apply:
                           Entity Employee is mapped to a table named EMPLOYEE.
                           Entity Cubicle is mapped to a table named CUBICLE.
                           Table EMPLOYEE contains a foreign key to table CUBICLE. The foreign key column is named
                           ASSIGNEDCUBICLE_<PK of CUBICLE>, where <PK of CUBICLE> denotes the name of
                           the primary key column of table CUBICLE. The foreign key column has the same type as the
                           primary key of CUBICLE, and there is a unique key constraint on it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值