Class ValidatingEntityCallback

java.lang.Object
org.springframework.data.mongodb.core.mapping.event.ValidatingEntityCallback
All Implemented Interfaces:
Ordered, EntityCallback<Object>, BeforeSaveCallback<Object>

public class ValidatingEntityCallback extends Object implements BeforeSaveCallback<Object>, Ordered
JSR-303 dependant entities validator.

When it is registered as Spring component its automatically invoked after object to Document conversion and before entities are saved to the database.

Since:
4.5
Author:
Rene Felgenträger, Mark Paluch
  • Constructor Details

    • ValidatingEntityCallback

      public ValidatingEntityCallback(jakarta.validation.Validator validator)
      Creates a new ValidatingEntityCallback using the given Validator.
      Parameters:
      validator - must not be null.
  • Method Details

    • onBeforeSave

      public Object onBeforeSave(Object entity, org.bson.Document document, String collection)
      Description copied from interface: BeforeSaveCallback
      Entity callback method invoked before a domain object is saved. Can return either the same or a modified instance of the domain object and can modify Document contents. This method is called after converting the entity to a Document so effectively the document is used as outcome of invoking this callback. Changes to the domain object are not taken into account for saving, only changes to the document. Only transient fields of the entity should be changed in this callback. To change persistent the entity before being converted, use the BeforeConvertCallback.
      Specified by:
      onBeforeSave in interface BeforeSaveCallback<Object>
      Parameters:
      entity - the domain object to save.
      document - Document representing the entity.
      collection - name of the collection.
      Returns:
      the domain object to be persisted.
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface Ordered