3

I am trying to solve the problem how should I create "logs" for my app and store them to database.

Let's assume I have this database structure:

FIRST TABLE:

weatherstation_id | weatherstation_name | weatherstation_ip_address

SECOND TABLE:

sensor_id | sensor_name | sensor_number | weatherstation_id

THIRD TABLE:

measurement_id | value | measure_date | weatherstation_id | sensor_id

from this I should be able to get the "log" so the measurement value and informations about the weather station and sensor !AT THE TIME WHEN THE MEASUREMENT WAS MADE!, so I need to implement history somehow.

I am trying to solve this for more than two weeks and I have discovered that I should probably go with something like SCD type 4 or 6.

One option which came to my mind is spring-data-envers which should handle the history, but here I don't know how I should "link" the measurement to the revision.

Second option is to write it on my own and use JPA Lifecycle Callbacks and have in my WeatherStation entity list of WeatherStationHistory and before any update or persist add the copy of current WeatherStation there and then have the Measurement pointing to this WeatherStationHistory.

So what I want to know is what is the best way to solve this problem and how to implement it in spring boot application.

I hope I have described my problem clearly. I will be grateful for any advice.

Jakub Znamenáček
  • 766
  • 1
  • 4
  • 18

1 Answers1

1

I think you should use the database level options for SCD. Although I don’t know if there’s any benefit to this if it’s implemented at the application level.

Nesd
  • 101
  • 1
  • 8