title: Entity with properties dependant on its generated ID
body: <p>I want to persist an entity along with a cipher of its ID (primary key) which is going to be attributed by the database when the entity is first persisted. The way I did this was by persisting twice, a first time for having an ID assigned, having a <code>@PostPersist</code> callback that assigns the 'encryptedID' property and persisting a second time to update the 'encryptedID' field. My entity looks like this:</p>
  
  <pre><code>import javax.persistence.*;
  
  @Entity
  @Table(name = "encryptions")
  public class EncryptionTest {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      long id;
  
      String encryptedID;
  
      @PostPersist
      void updateEncryptedID(){
          this.encryptedID = encrypt(id);
      }
  
      private String encrypt(long idToEncrypt){
          return "encrypted_" + idToEncrypt ;
      }
  }
  </code></pre>
  
  <p>Is there a better way to do this though, without having to persist twice? </p>