title: Jpa is getting inconsistent data, from MySQL database
body: <p>I am using Jpa in order to communicate with database, but the data I am taking in inconsistent. I have a user class that has a OneToOne relationship with a Teacher class.</p>
  
  <pre><code>@OneToOne(mappedBy="user")
  private Teacher teacher; // From user class
  
  @OneToOne(cascade=CascadeType.ALL)
  @JoinColumn(name="user_id", referencedColumnName="id")
  private User user;  // from the teacher class
  </code></pre>
  
  <p>I am saving a teacher in the following way:</p>
  
  <pre><code>public Teacher save(Teacher teacher, Long id)
  {
      User user;
      Optional&lt;User&gt; ifUser = userRepo.findById(id);
      if(ifUser.isPresent()) {
          user= ifUser.get();
          user.setTeacher(teacher);
          user.setCompletedInfo(1);
          teacher.setUser(user);
          return teacherRepo.save(teacher);
      }else {
          System.out.println("Couldn't find any user here...");
          return null;
      }
  }
  </code></pre>
  
  <p>Where userRepo and teacherRepo are interfaces that extend from JpaRepository. Until now it works pretty cool. The information gets updated in the database. But when I get the info from the database, it shows me that</p>
  
  <pre><code> user.getCompletedInfo()
  </code></pre>
  
  <p>is null. Meanwhile I can see in the database that that value:</p>
  
  <pre><code>user.getCompletedInfo() =1;
  </code></pre>
  
  <p>The database is MySql, and a possible approach to the problem I would think is that I am getting some info from a new User Object that is being created somewhere.
  For more the project is in Github: <a href="https://github.com/shpendpalushi/JavaWeb/tree/For_Project" rel="nofollow noreferrer">https://github.com/shpendpalushi/JavaWeb/tree/For_Project</a></p>
  
  <p>Edit:
  From some Unit testing I was able to find that in the teacher service setUser wasn't  doing it's job properly. When I tried to getUser it returned me a null;
  Am I doing something wrong in the save method?</p>