title: Spring JPA - Stackoverflow exception on updating Owning end of OnetoOne relation
body: <p>I have a <code>one-to-one</code> mapping between two Objects. </p>
  
  <p><strong>UserDO.java:</strong></p>
  
  <pre><code>public class UserDO {
  
      @Id
      @GeneratedValue
      private Long id;
  
      @Column(nullable = false)
      @NotNull(message = "Username can not be null!")
      private String username;
  
      @Column(nullable = false)
      @NotNull(message = "Password can not be null!")
      private String password;
  
      @Column(nullable = false)
      private Boolean deleted = false;
  
      @Enumerated(EnumType.STRING)
      @Column(nullable = false)
      private OnlineStatus onlineStatus;
  
      @Column(nullable = false)
      @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
      private ZonedDateTime dateCreated = ZonedDateTime.now();
  
      @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
      private CardDO card;
  
  }
  </code></pre>
  
  <p><strong>CardDO.java:</strong></p>
  
  <pre><code>public class CardDO {
  
      @Id
      @GeneratedValue
      @Column(name="id")
      private Long id;
  
      @Column(nullable = false)
      private Long pan;
  
      @Column(nullable = false)
      @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
      private LocalDate expirationDate;
  
  
      @Enumerated(EnumType.STRING)
      @Column(nullable = false)
      private CardType cardType;
  
  
      @Column(nullable = false)
      @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
      private ZonedDateTime dateCreated = ZonedDateTime.now();
  
      @OneToOne(mappedBy="card")
      private UserDO user;
  
  }
  </code></pre>
  
  <p>Now, when i link the two up first time and save the user object in repo it works fine but everytime when i try to update the user object, it throws StackOverFlow exception.</p>
  
  <p>Code for linking the 2 objects up:</p>
  
  <pre><code>userDO.setCard(cardDO);
  userRepository.save(userDO);
  </code></pre>
  
  <p>Code for updating:</p>
  
  <pre><code>UserDO userDO = findUser(userId);
  userDO.setOnlineStatus(onlineStatus);
  userRepository.save(userDO);
  </code></pre>
  
  <p>What could be wrong? </p>