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:
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.
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.