hi,

On Mon, 11 Aug 2003 16:18:25 -0400, "Gerry Duprey"
<[EMAIL PROTECTED]> said:

> We have an application where we need to keep a version of every change to a 
> record in a table ever made and the effective date it was created/changed on 
> each version.  The number of changes are low (one or two a year per "record").
> 
> I've been planning on doing this by having a unique serial # assigned to every 
> record (typical PK), but also have a unique key commonly assigned to a 
> logically related set of records.  Consider a new Employee record - the PK 
> would be assigned normally as well as a seperate "employee-id" assigned from 
> another sequence. Later when this record is changed, we keep a copy of the old 
> record untouched and create a new record to reflect the new changes. 

i think a better way to look at this is to keep the entity and its state
at a particular point in time separate in your model. the entity just has
a collection of "mementos" with timestamps... this of course can be
encapsulated behind some convenience methods, eg.

class Employee {
  ...
  public BigDecimal getSalary(Date date) {
    return this.getState(date).getSalary();
  }

  // setters create a new state/memento
}

ideally this will be mapped into two tables: one to keep the immutable
state of the entity (incl. PK), one to keep the details that change over
time... this way you can also set up the appropriate integrity
constraints in the DB too...

changes to the object will result in an INSERT, and with appropriate lazy
loading, you can avoid fetching all versions all the time. 

regards,
     viktor

-- 
http://www.fastmail.fm - Or how I learned to stop worrying and
                          love email again


-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to