- In this kind of association, a foreign key column is created in owner entity. For example, if we make EmployeeEntity owner, then a extra column "ACCOUNT_ID" will be created in Employee table. This column will store the foreign key for Account table.
- To make such association, refer the Account entity in EmployeeEntity class as follow:
@OneToOne @JoinColumn(name="ACCOUNT_ID") private AccountEntity account;
- @JoinColumn
- The join column is declared with the @JoinColumn annotation which looks like the @Column annotation, It is used in column owner column and mapped by used in other table. It has one more parameters named referencedColumnName. This parameter declares the column in the targeted entity that will be used to the join.
- mappedBy
- mappedBy is used. ‘mappedBy’ refers to the property name of the association on the owner side.AccountEntity.java
-
@OneToOne(mappedBy="account") private EmployeeEntity employee;
Wednesday, 5 December 2018
Hibernate one to one mapping
About Unknown
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment