We are implementing the data change history function using Hibernate CustomEventListener. Detects when values are modified through JPA’s save or saveAll through PostUpdateEventListener.
@Override
public void onPostUpdate(PostUpdateEvent event) {
if (!Objects.equals(beforeValue, afterValue)) {
changeDataService.save();
}
}
Currently, we are loading the change history log by inheriting PostUpdateEventListener, creating a class, comparing change values within the onPostUpdate() method, and saving the change history to RDB using the changeDataRepository.save()
code.
Values using JPA’s save method are loaded properly, but when the saveAll method is used, the data is not loaded into the changeData table. When I log the query, I see that when using save, the insert query loaded into the changeData table works well, but when saveAll is used, the insert query loaded into the changeData table is not executed.
I thought the problem was caused by not committing when saving the change history, so I added @Transaction to the save method that creates and saves the change history-related service, but the error situation was not resolved.
How can the change history of data modified with saveAll be properly loaded into the changeData table?
박지영 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.