title: Implementing a data history / versioning solution for a Hibernate-based application (with a twist)
body: <p>First the basic facts: Java webapp, Spring, Hibernate, MySQL.</p>
  
  <p>The situation is that I have a complex object model of e.g. a <strong>Car</strong>. It's
  composed of many objects (Engine, Tires, ...) with many-to-one and one-to-many relationships between them.  </p>
  
  <p>Now there are many cars, and every now and then someone inspects a car and creates a <strong>Report</strong> of the inspection. Report refers to the many parts that car, displaying their properties etc.</p>
  
  <p>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. </p>
  
  <p>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.</p>
  
  <p>I've been looking at "<a href="http://en.wikipedia.org/wiki/Slowly_changing_dimension#Type_6_.2F_Hybrid" rel="noreferrer">Slowly changing dimensions</a>" and it seems that the versioning of the car and its parts could be done with the Type 6 approach. </p>
  
  <p>The thing (the twist) that I'm having trouble figuring out (probably due to my limited Hibernate experience) is this:</p>
  
  <p><strong>How can I assemble my Report instances with Hibernate so that they refer to the correct versions of each part of the car?</strong> 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. <strong>But is there any easier, more automatic way to do it with Hibernate?</strong></p>