Module spring.data.mongodb
Interface BeforeSaveCallback<T>
- All Superinterfaces:
EntityCallback<T>
- All Known Implementing Classes:
ValidatingEntityCallback
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Entity callback triggered before save of a document.
- Since:
- 2.2
- Author:
- Mark Paluch, Michael J. Simons
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiononBeforeSave(T entity, org.bson.Document document, String collection) Entity callback method invoked before a domain object is saved.
-
Method Details
-
onBeforeSave
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 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.- Parameters:
entity- the domain object to save.document-Documentrepresenting theentity.collection- name of the collection.- Returns:
- the domain object to be persisted.
-