title: Update/Merge all fields of a detached entity with new instance of same class - in Spring Boot
body: <p>I've implemented the following inheritance.</p>
  
  <pre><code>abstract Superclass: ConnectionTechnologyDetails
  Subclasses: SMTPDetails, AS2Details and FTPDetails
  </code></pre>
  
  <p>Instances of the subclasses are persisted with the JPA repositories of Spring. New data arrives from a front end form, saved in new instances of the subclasses.</p>
  
  <p>Unfortunately I can't manage to update the persisted entites with the fields of the new instaces. Because I don't know the actual class of the instances I can't use their setters. Only the setters of the superclass ConnectionTechnologyDetails are available.</p>
  
  <pre><code>// getting the id of the persisted entity
  Long connectionTechnologyDetailsDetachedId = connectionPersisted.getConnectionTechnology()
      .getConnectionTechnologyDetails()
      .getId();
  
  // detach the persistent entity
  ConnectionTechnologyDetails connectionTechnologyDetailsDetached = 
      connectionTechnologyDetailsRepository
      .findById(connectionTechnologyDetailsDetachedId).get();
  </code></pre>
  
  <p>I would like to update like that:</p>
  
  <pre><code>/** Update all fields with the fields of the 
  *   new instance because I can't access
  *  the setters and getters of the subclasses here.
  */
  
  connectionTechnologyDetailsDetached
      .updateALlFieldsWith(
          connectionRequest
          .getConnectionTechnology()
          .getConnectionTechnologyDetails()
      );
  connectionTechnologyDetailsRepository.save(connectionTechnologyDetailsDetached);
  </code></pre>
  
  <p><strong>Is there some method to update all fields or maybe a possibility to access the setters and getters of the subclasses?</strong></p>
  
  <p>My solution so far: Get the specific subclass from the DiscriminatorColumn annotation of the subclasses. Then cast to the specific class and call manually all setters with the new values.</p>