What are you are trying to do requires dealing (at the very least) with these issues:
- What are you going to do with primary keys?
The simplest thing is to generate a new id. But then the auditing mechanism must have a way of associating the new id with the old id. Presumably that table would look something like (object_id, old_version_id, change_date) with the primary key of (object_id, old_version_id). Of course, keys of more than one column make it more complicated.
- What are you going to do with unique constraints?
The primary key case is just a special case of a unique constraint. Any other unique constraints in your model needs to be handled. The interceptor can simply uniquify values, e.g. by appending a timestamp. Or you can not have unique constraints. Another option is to use a separate table for all old values. That table can omit the unique constraints and have a primary key along the lines described above, (object_id, old_version_id).
- What are you going to do with one-to-many or many-to-many associations?
Auditing *-to-many associations is not as simple as recording an old value, because there are many values. You could record the whole collection of values as of each change to the association, or you could record just what changes are made.
- What are you going to do with inverse associations?
If old data is in the same table as new data, foreign key references to the audited table need to be handled in a manner that does not leave them pointing at old data.
- What about deletion of associated objects?
Old data that has foreign keys needs to deal with deletion of the referenced object. This could be as simple as not using foreign keys in the auditing data, or declaring those keys as "on delete cascade" or "on delete set null".
It may be that none of these problems affect your use case. If so, it
would help to understand what you are trying to do in a little more detail.
However, I imagine that these problems make it difficult to submit a patch
that adds support for the Auditable interface as proposed.
-- Archit Shah ([EMAIL PROTECTED])
On Thursday, Apr 22, 2004, at 13:59 US/Eastern, Lendvai Attila wrote:
in short: can i achive from an interceptor that entities that implement Auditable and are (directly/indirectly) passed to saveOrUpdate() will automatically be saved into a new row?
any hints how to implement in Hibernate for a patch candidate?
------------------------------------------------------- This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek For a limited time only, get FREE Ground shipping on all orders of $35 or more. Hurry up and shop folks, this offer expires April 30th! http://www.thinkgeek.com/freeshipping/?cpg=12297 _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel