I use NHibernate interceptors to log update / insert / delete information for my various objects.
Included in the registered information is the type of object and the unique identifier of the object that has been changed. The unique identifier is marked as <generator class="identity"> in the NHibernate mapping file.
The obvious problem is that when registering an Insert operation using IInterceptor.OnSave (), an object identifier has not yet been assigned.
How can I get the ID of an inserted object before recording audit information?
(I watched the PostSave event for NHibernate Listeners, but I can't get them to work with my Spring.net configuration, so I would like to stick with interceptors, if at all possible)
code:
// object id parameter is null... public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types) { AddAuditItem(entity, INSERT); return false; }
Tone source share