title: Spring Data MongoDB BeforeSaveCallback not working
body: <p>I want to have similar functionality as I get with the JPA <code>@PrePersist</code> but in a mongodb database. Reading the spring data mongodb documentation I found the entity callbacks: <a href="https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#entity-callbacks" rel="nofollow noreferrer">https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#entity-callbacks</a>. They seem to work for what I need so I'm trying to implement some callbacks. I know there are some alternatives for what I'm doing (auditing annotations) but I want to keep with this for the moment.</p>
  
  <p>This is how I register the callback, my entity definition and the repository:</p>
  
  <pre><code>@Configuration
  public class BeforeSaveCallbackConfiguration {
  
      @Bean
      BeforeSaveCallback&lt;Measurement&gt; beforeSaveMeasurement() {
          return (entity, document, collection) -&gt; {
              entity.setTimestamp(System.currentTimeMillis());
              System.out.println("Before save, timestamp: " + entity.getTimestamp());
              return entity;
          };
      }
  }
  
  public interface MeasurementRepository extends MongoRepository&lt;Measurement, String&gt; {
  }
  
  @Document
  public class Measurement {
  
      private String id;
      private long timestamp;
      private Float value1;
      private Float value2;
      // constructor, getters, setters ...
  }
  </code></pre>
  
  <p>I save the entity using <code>measurementRepository.save</code> method of the repository. I actually see the printed line from the callback with the timestamp. However the data saved in the mongodb collection always have timestamp set to 0. Does anyone have any hint?</p>