Howdy All,

I've been getting into Hibernate for the last week and I'm so impressed. Which wouldn't be hard after how depressed I was with JDO and the in ability to support rational inheritence and SCOs. Anyway...

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. That new record would have a unique/new PK, but would have the same employee-id as the original record. To discriminate which record is the "current" one, there is an "effective-date" field and depending on what the date you are interested in decides on which record is considered current.

With this and a simple query, I can pull up a copy of the employee record as it looked for any date. Works great.

I'm now trying to integrate the creation of the versioned records into a base "versioned" class to be used with Hibernate. Basically, what I need to do is in the LifeCycle onSave method, convert the current record/object into a "new" one to force the previous/old version to continue to exist and have Hibernate assign a new PK to this record.

I have two questions which I have not been able to figure out:

1) Does Session.getIdentifier() have a setter like like setIdentifier()? Basically, I want to change the object state to "new" and have Hibernate assign a new OK and do an INSERT into the DB (vs an UPDATE). I beleive I can do that by Sessions.setIdentifier(myObject, null).

2) If there is such a method, can it be invoked from the onSave() LifeCycle method? My concern was whether Hibernate decides if the flush is an update or save/new by looking at the key BEFORE the onSave() method is invoked (in which case I'm in trouble) or after (in which case, assuming I can clear the Identifier, I should be good).

I'm still scanning the API docs, but haven't come across these items that I'd need. If anyone has any suggestions on where to look or if I seem to be going off and making something more complicated than it has to, I'd really appreciate your help.

Thanks!!

Gerry

--
Gerry Duprey
________________________________________
SchoolsOPEN, LLC
123 North Ashley, Suite 120
Ann Arbor, MI 48104
Phone (877) 483-1944 Ext. 401
Fax (734) 661-0819

Visit us Online at www.Schools-OPEN.com




------------------------------------------------------- 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