title: How to override JPA @PrePersist behaviour for a unit test
body: <p>I have the following JPA entity:</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Builder
  @Table(name = &quot;My_Table&quot;)
  public class MyTableEntity {
  
      @Column(name = &quot;id&quot;)
      private long id;
  
      @Column(name = &quot;creationdatetime&quot;)
      private LocalDateTime creationDateTime;
  
      @Column(name = &quot;updatedatetime&quot;)
      private LocalDateTime updateDateTime;
  
      @PrePersist
      protected void onCreate() {
      this.creationDateTime = LocalDateTime.now();
          this.updateDateTime = LocalDateTime.now();
      }
  }
  </code></pre>
  <p>I have a unit test where I am doing this:</p>
  <pre class="lang-java prettyprint-override"><code>   LocalDateTime creationDate = LocalDateTime.now().minusDays(100);
     MyTableEntity entity = 
     MyTableEntity.builder()
             .id(1)
             .build();
     entity.setCreationDateTime(creationDate)
     entity.setUpdateDateTime(creationDate)
  </code></pre>
  <p>However, later on in my unit test, the value I'm setting for creation date time and update date time  is magically getting changed as per what is defined in the <code>@PrePersist</code> method in my JPA entity.</p>
  <p>Solely for the purpose of unit testing, how can I stop <code>@PrePersist</code> from overriding values I'm explicitly setting during the unit test?</p>
  <p>(If it, helps I am using Mockito.)</p>