title: How to remove foreign key without deleting the whole entity
body: <p>I am new to Spring boot and I want to be able to delete the value of a forgein key if its entity is removed without deleting the whole entity linked to it; I explain in my case a single person who has an Account can be at the same time an Author and a Player, so if I delete an author I want to delete its refrence in Account table without deleting the whole account because this account can still point on player. I searched on the internet I found cascadetype but it will delete the whole account!</p>
  <p>Thank you in advance!
  here is my entities</p>
  <pre><code>@Table(name = &quot;account&quot;)
  @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
  public class Account implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = &quot;sequenceGenerator&quot;)
      @SequenceGenerator(name = &quot;sequenceGenerator&quot;)
      @Column(name = &quot;ID&quot;)
      private Long id;
  
      @ManyToOne
      @JoinColumn(name = &quot;Author&quot;)
      private Author author;
      
      @ManyToOne
      @JoinColumn(name = &quot;Player&quot;)
      private Player player;
  
      //attributs, getters &amp; setters
  }
  
  @Table(name = &quot;player&quot;)
  @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
  public class Player implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = &quot;sequenceGenerator&quot;)
      @SequenceGenerator(name = &quot;sequenceGenerator&quot;)
      @Column(name = &quot;ID&quot;)
      private Long id;
  
     //attributs, getters &amp; setters
  }
  
  
  //ma.myapp.usersgestion.domain.Author
  
  @Table(name = &quot;author&quot;)
  @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
  public class Author implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = &quot;sequenceGenerator&quot;)
      @SequenceGenerator(name = &quot;sequenceGenerator&quot;)
      @Column(name = &quot;ID&quot;)
      private Long id;
  
      @OneToMany(mappedBy = &quot;author&quot;)
      @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
      @JsonIgnoreProperties(value = { &quot;player&quot;, &quot;author&quot;}, allowSetters = true)
      private Set&lt;Account&gt; accounts = new HashSet&lt;&gt;();
  
     //attributs, getters &amp; setters
  }
  </code></pre>
  <p>UPDATE</p>
  <p>Im using jhipster (spring boot with React) and h2 database (with disk-based persistence)</p>
  <pre><code>//AuthorResource.java
  @RestController
  @RequestMapping(&quot;/api&quot;)
  @Transactional
  public class AuthorResource {
  
      private final Logger log = LoggerFactory.getLogger(AuthorResource.class);
  
      private static final String ENTITY_NAME = &quot;author&quot;;
  
      @Value(&quot;${jhipster.clientApp.name}&quot;)
      private String applicationName;
  
      private final AuthorRepository authorRepository;
  
      public AuthorResource(AuthorRepository authorRepository) {
          this.authorRepository = authorRepository;
      }
  /**
       * {@code DELETE  /authors/:id} : delete the &quot;id&quot; author.
       *
       * @param id the id of the author to delete.
       * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
       */
      @DeleteMapping(&quot;/authors/{id}&quot;)
      public ResponseEntity&lt;Void&gt; deleteAuthor(@PathVariable Long id) {
          log.debug(&quot;REST request to delete Author : {}&quot;, id);
          authorRepository.deleteById(id);
          return ResponseEntity
              .noContent()
              .headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString()))
              .build();
      }
     
  //...
  }
  
  //AuthorRepository
  
  @SuppressWarnings(&quot;unused&quot;)
  @Repository
  public interface AuthorRepository extends JpaRepository&lt;Author, Long&gt; {}
  </code></pre>