title: JPA integrity constraint violated - parent key not found when trying to save entity with JoinColumn
body: <p>I am trying to save a User Entity with Roles under it. It seems like since the roles do not have their user id foreign key set it fails to save, is there a way to tell jpa to set the role's user id after it saves the user but before it saves the user's roles? Or will I need to remove the cascade save, save the User, set the role user ids, and then save the roles manually?</p>
  <pre><code>import lombok.*;
  
  import javax.persistence.*;
  import java.sql.Timestamp;
  import java.util.List;
  
  @Entity
  @Table(name = &quot;USER&quot;)
  @Data
  @Builder
  @AllArgsConstructor
  @NoArgsConstructor
  @EqualsAndHashCode(callSuper = true)
  public class User {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long userId;
  
      @JoinColumn(name = &quot;userId&quot;, referencedColumnName = &quot;userId&quot;)
      @OneToMany(cascade=CascadeType.ALL)
      private List&lt;UserRoles&gt; userRoles;
  
  }
  </code></pre>
  <p>and roles:</p>
  <pre><code>import lombok.*;
  
  import javax.persistence.*;
  
  @Entity
  @Table(name = &quot;USER_ROLES&quot;)
  @Data
  @Builder
  @AllArgsConstructor
  @NoArgsConstructor
  @EqualsAndHashCode(callSuper = true)
  public class UserRoles {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long userRolesId;
  
      @Column
      private long userId;
  
      @Column
      private long roleId;
  
  }
  </code></pre>
  <p>Error from calling UserRepository.save(user) when roles are present:</p>
  <pre><code>oracle.jdbc.OracleDatabaseException: ORA-02291: integrity constraint (APP_OWNER.SYS_C009043) violated - parent key not found
  </code></pre>
  <p>The SYS_C009043 constraint is a foreign key constraint in the USER_ROLES table requiring userId to exist in the USER table</p>