I am confused in owner in relationship with hibernate.
what exactly is owner(owner side) in association?
I want to study Mappedby and inverse. please help.
As a general rule the owning side of a relation would the side which you'd need to update for the change of the relation to be persisted.
If you are mapping the entities to a relational database (most probably the case) the owning side often can be identified as the entity whose table contains the foreign key.
In the entities themselves mappedBy
would refer to the owning side and thus is placed on the inverse side of the relation.
In 1:n relations in most cases the owning side is the n side, in n:m relations, 1:1 relations or 1:n with mapping tables you can choose either side, just choose one.
Example:
class Thread {
@OneToMany( mappedBy = "thread" )
List<Entry> entries;
}
class Entry {
@ManyToOne
Thread thread;
}
In the example, the owning side would be the Entry
entity, since you need to change the value of Entry#thread
to change the thread an entry belongs to. Just adding/removing an entry to/from Thread#entries
wouldn't make the changes persisted in most cases (orphanRemoval
and the like would still have an effect if done correctly).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With