Background
----------

Suppose we have bidirectional `OneToOne` relationship. 
There are `User` and `Address` entity. `User` has many `Address`es.

```
CREATE SEQUENCE IF NOT EXISTS hibernate_sequence;
CREATE TABLE users (
  id BIGINT PRIMARY KEY
);

CREATE TABLE addresses (
  id BIGINT PRIMARY KEY,
  user_id BIGINT NOT NULL UNIQUE CONSTRAINT fk_addresses_user_id REFERENCES users(id) ON DELETE CASCADE,
);

```

and

```
@Table(name = "users")
public class User {

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE)
  private Long id;

  //mappings
  private Address address;
}

@Table(name = "addresses")
public class Address {

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE)
  private Long id;

  //mapings
  private User user;
}

```

Disclaimer:
-----------

I'm using `OneToOne` as an example but the question is about relations in general so the right approach is valid for `ManyToMany` as well.

TL;DR - the question is about using `mappedBy<->relation owner<->cascades<->managing other side in setters` in general

Questions:
----------

1. In database there should be user\_id in address table table, right? Who is the owner of the relation then?
2. In entities: which one should have mappedBy - (`User` or `Address`) / (Owner or Inverse)?
	* This link: <https://coderanch.com/t/595728/databases/Newbie-Hibernate-OneToMany-owning-side> states: "Note that the mappedBy automatically makes the relationship the inverse or non-owning side." so `Address` should have mappedBy
	* While in this link: <https://vladmihalcea.com/the-best-way-to-map-a-onetoone-relationship-with-jpa-and-hibernate/> `Post` (`User` in my example) have mappedBy to `PostDetails` (`Address` in my example)
	* Javadoc: <https://docs.oracle.com/javaee/7/api/javax/persistence/OneToOne.html#mappedBy()> says "The field that owns the relationship" so `User` owns the relation, and therefore `Address` should have mappedBy (`CustomerRecord` in JavaDoc)
	* But hibernate documentation: <http://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#associations-one-to-one-bidirectional> the parent `Phone` (`Person` in my example) has mappedBy to `PhoneDetails` (`Address`)
3. On which side (`User` or `Address`) / (mappedBy or inverse-side) the `@OneToOne(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH})` should be placed?
4. And last question: which of the entities should manage the relation like this:

```
public void addAddress(Address address) {
  if (address != null) {
    address.addUser(this);
  }
  this.addresses.add(address);
}

public void removeAddress(Address address) {
  if (address != null) {
    address.removeUser(this);
  }
  this.addresses.remove(address);
}

public Set<Address> getAddresses() {
  return Collections.unmodifiableSet(this.addresses);
}

```

the (`User` or `Address`) / (mappedBy or inverse-side)?

* This link: <https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/> shows the approach listed above (where the parent, `User` in my example, manages the relation)
* But here: <https://www.quora.com/What-is-the-purpose-of-mapped-by-element-in-OneToMany-annotation-in-Hibernate> Vlad says: "it’s always good practice if the child side, where the Foreign Key is located, controls the association", so the Address should "controll the relation" (exactly the opposite)?

Moreover - look at theese two links:

* <https://docs.oracle.com/javaee/7/api/javax/persistence/OneToOne.html> - here CustomerRecord has mappedBy
* <https://docs.oracle.com/javaee/7/api/javax/persistence/OneToMany.html> - but here Customer has mappedBy!

Thank you in advance

PS. Previous version of my question was using `OneToMany` as an example, but because inverse - `ManyToOne` does not have mapped by I changed it to `OneToOne` which better shows the problem