Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing a data history / versioning solution for a Hibernate-based application (with a twist)

First the basic facts: Java webapp, Spring, Hibernate, MySQL.

The situation is that I have a complex object model of e.g. a Car. It's composed of many objects (Engine, Tires, ...) with many-to-one and one-to-many relationships between them.

Now there are many cars, and every now and then someone inspects a car and creates a Report of the inspection. Report refers to the many parts that car, displaying their properties etc.

So far the system hasn't supported the ability to update the car's and its parts' properties once they have been fed into the system. Meaning that if a color of the chassis or number of tires were changed, the old reports would reflect this change which is not what we want.

Well, now this feature has been requested. The cars and their parts need to be modifiable and a version history has to be created. The old reports need to refer to the old versions of the parts and their values.

I've been looking at "Slowly changing dimensions" and it seems that the versioning of the car and its parts could be done with the Type 6 approach.

The thing (the twist) that I'm having trouble figuring out (probably due to my limited Hibernate experience) is this:

How can I assemble my Report instances with Hibernate so that they refer to the correct versions of each part of the car? The reports have a date and each version of the car parts would have date ranges when they were the valid, so I guess I could do it with some complex HQL/SQL. But is there any easier, more automatic way to do it with Hibernate?

like image 875
Janne Avatar asked Dec 22 '09 10:12

Janne


1 Answers

You can take a look at JBoss envers for versioning your objects. I'm not sure that it is suitable for your usecase, but give it a look.

like image 123
Bozho Avatar answered Sep 18 '22 18:09

Bozho