Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play! Framework Historical Data Changes

I have an application I'm building in Play! Framework with a bunch of data that I would like to track changes to. In a enterprise solution, I would likely use database triggers to copy the changes to a historical table to track those changes. I am not familiar with a similar paradigm in Play!/JPA, but maybe I'm missing something. Is there a decent way to do this other than me creating a copy of all of my entities and manually copying the data from the old/unchanged record to the historical, then saving the changes to the original model?

like image 239
Benny Avatar asked May 20 '26 20:05

Benny


1 Answers

If you data is very critical to keep all the data changes I would stick with the triggers. Because as database doing the updates so there is no possible clock skew in the cluster running the web app and if a non-JPA client accesses the database then you could keep updates as well.

However, if you are not so obsesive about these kind of concerns than I would suggest you magic EntityListeners such as:

  • @PrePersist
  • @PreUpdate
  • @PreRemove
  • @PostPersist
  • @PostUpdate
  • @PostRemove

Here you could find examples of how to use EntityListener,

like image 81
huzeyfe Avatar answered May 23 '26 10:05

huzeyfe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!