title: JPA - Hibernate - OneToOne
body: <p>I have a OneToOne relation between tables User and Profile defined like so:</p>
  <pre><code>@Entity
  @Builder
  @Data
  @NoArgsConstructor
  @AllArgsConstructor
  @Table(name=&quot;users&quot;, uniqueConstraints = { 
          @UniqueConstraint(columnNames = &quot;username&quot;),
          @UniqueConstraint(columnNames = &quot;email&quot;)
      }
  )
  public class User implements Serializable {
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
      
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int idUser;
      private String username;
      private String email;
      private String password;
      
      @OneToOne(cascade=CascadeType.ALL, orphanRemoval=true)  
      @JoinColumn(name=&quot;id_profile&quot;, referencedColumnName=&quot;idProfile&quot;)
      private Profile profile;
      
      @ManyToMany(fetch = FetchType.EAGER)
      private Set&lt;Role&gt; roles = new LinkedHashSet&lt;Role&gt;();
  
  }
  </code></pre>
  <pre><code>@Entity
  @Data
  @Builder
  @NoArgsConstructor
  @AllArgsConstructor
  @Table(name=&quot;profile&quot;,
      uniqueConstraints = @UniqueConstraint(columnNames = &quot;discordId&quot;)
  )
  public class Profile implements Serializable {
      
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int idProfile;
      private Date birthday;
      private String discordId;
      private String description; 
      @ElementCollection(fetch=FetchType.EAGER)
      private Set&lt;String&gt; spokenLanguages = new LinkedHashSet&lt;String&gt;();
  
      @OneToMany(fetch=FetchType.EAGER)
      private Set&lt;ProfileGame&gt; profileGames = new LinkedHashSet&lt;&gt;();
      
      @OneToOne(mappedBy=&quot;profile&quot;)
      private User user;
      
      @ManyToOne
      private TimeSlot timeSlot;
      
  }
  </code></pre>
  <p>Then I run a test to make some fixtures in my database:</p>
  <pre><code>Profile profile = this.profileRepository.save(Profile.builder()
                      .birthday(new Date())
                      .discordId(&quot;discord-&quot; + i)
                      .description(&quot;Description de user-&quot; + i)
                      .spokenLanguages(spokenLanguages)
                      .timeSlot(timeSlot)
                      .build());
              user.setProfile(profile);
              System.err.println(user);
  </code></pre>
  <p>Everything works fine here, System.err.println(user) returns correct values.</p>
  <p>The issue comes from the database, which doesn't &quot;apply&quot; the id_profile in my User table:</p>
  <p><a href="https://i.stack.imgur.com/du3q4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/du3q4.png" alt="enter image description here" /></a></p>
  <p>What did I miss?</p>