Class ValidatingEntityCallback
java.lang.Object
org.springframework.data.mongodb.core.mapping.event.ValidatingEntityCallback
- All Implemented Interfaces:
Ordered, EntityCallback<Object>, BeforeSaveCallback<Object>
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, HeeChul Yang
-
Field Summary
Fields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionValidatingEntityCallback(jakarta.validation.Validator validator) Creates a newValidatingEntityCallbackusing the givenValidator. -
Method Summary
Modifier and TypeMethodDescriptionintgetOrder()onBeforeSave(Object entity, org.bson.Document document, String collection) Entity callback method invoked before a domain object is saved.voidsetOrder(int order) Specify the order value for thisBeforeConvertCallback.
-
Constructor Details
-
ValidatingEntityCallback
public ValidatingEntityCallback(jakarta.validation.Validator validator) Creates a newValidatingEntityCallbackusing the givenValidator.- Parameters:
validator- must not be null.
-
-
Method Details
-
getOrder
-
setOrder
public void setOrder(int order) Specify the order value for thisBeforeConvertCallback.The default value is
100.- Since:
- 5.0
- See Also:
-
onBeforeSave
Description copied from interface:BeforeSaveCallbackEntity callback method invoked before a domain object is saved. Can return either the same or a modified instance of the domain object and can modifyDocumentcontents. This method is called after converting theentityto aDocumentso 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 theBeforeConvertCallback.- Specified by:
onBeforeSavein interfaceBeforeSaveCallback<Object>- Parameters:
entity- the domain object to save.document-Documentrepresenting theentity.collection- name of the collection.- Returns:
- the domain object to be persisted.
-