Lifecycle Events
Spring Data JDBC triggers events that get published to any matching ApplicationListener
beans in the application context.
For example, the following listener gets invoked before an aggregate gets saved:
@Bean
public ApplicationListener<BeforeSave> timeStampingSaveTime() {
return event -> {
Object entity = event.getEntity();
if (entity instanceof Category) {
Category category = (Category) entity;
category.timeStamp();
}
};
}
The following table describes the available events:
Event | When It Is Published |
---|---|
Before an aggregate root gets deleted. |
|
After an aggregate root gets deleted. |
|
Before an aggregate root gets saved (that is, inserted or updated but after the decision about whether if it gets updated or deleted was made). |
|
Before an aggregate root gets saved (that is, inserted or updated but after the decision about whether if it gets updated or deleted was made). |
|
After an aggregate root gets saved (that is, inserted or updated). |
|
After an aggregate root gets created from a database |
Lifecycle events depend on an ApplicationEventMulticaster , which in case of the SimpleApplicationEventMulticaster can be configured with a TaskExecutor , and therefore gives no guarantees when an Event is processed.
|
Store-specific EntityCallbacks
Spring Data JDBC uses the EntityCallback
API for its auditing support and reacts on the following callbacks:
EntityCallback |
When It Is Published |
---|---|
Before an aggregate root gets deleted. |
|
After an aggregate root gets deleted. |
|
Before an aggregate root gets saved (that is, inserted or updated but after the decision about whether if it gets updated or deleted was made). |
|
Before an aggregate root gets saved (that is, inserted or updated but after the decision about whether if it gets updated or deleted was made). |
|
After an aggregate root gets saved (that is, inserted or updated). |
|
After an aggregate root gets created from a database |