Originally posted by Amandeep Singh:
Chaminda,
i thought the concept of owner relationship lies in the fact on which side we do use the mappedBy attribute. Suppose-
So now the parent table will be CarBillingInfo entity because it is using the mappedBy attribute as the owning side of the relationship.
------------------
@OneToOne(mappedBy = "carBillingInfo", optional = false)
protected Car car;
------------------
it will be the child table Car.
--------------
@OneToOne
protected CarBillingInfo carBillingInfo;
----------------------
Please correct me if i am wrong.
In One to One bidirectional your understanding is not correct, mappedBy att. defines according to the relationship exist. mappedBy att. does not define the owner of O2O bi relationship
In O2O bi, ownership is defined by its table structure. ie. by who holds others primary key as his foreign key
Lets get an example,
Employee has exactly one PersonalInfomationFile and vise versa
Employee Table
---------
id
personalInfomationFile (fk PersonalInfomationFile.id)
// this is id field of PersonalInfomationFile //and other columns
PersonalInfomationFile Table
---------
id
//and other columns
In this case Employee table holds PersonalInfomationFile's id as a foreign key. So Employee is the owner. Therefor you must put mappedBy in PersonalInfomationFile class
This explanation is true for O2M as well. Many side holds one side's id always as a foreign key. So that's why many side always becomes the owner.
in manay to many either table doesnt keep other's id. so you can define owner in either side.