I am looking for a simple definition for “owner”. The hibernate docs talk about the “owner” all the time, but I can’t find any definition for what the owner is. That is, I’d like to be able to answer the following kinds of questions:
- What does it mean, conceptually/logically, to be the owner?
- Does this correspond to any concept in real life?
- In a many-to-one or one-to-many relationship, why would you choose one end or the other as being the owner?
The owner is the side which doesn’t have the
mappedByattribute.It’s the side of the association that Hibernate/JPA tracks to see if the association exists or not between two entities. If you set/modify the owner side, the change will be reflected in the database. If you set/modify the other side, JPA/Hibernate doesn’t care.
It doesn’t correspond to any concept in real life.
In a bidirectional OneToMany/ManyToOne assoaciation, the only side that can be the owner in the JPA spec is the Many side. It’s also the most natural choice given that it’s the many side which is mapped to the table holding the foreign key which materializes the association. Hibernate allows defining the other side as the owner, but the mapping is complex, and not advised.