It is similar to audit logging, but we don't have different table to record audit log information.
What we have in all our table is this 2 column ModifiedBy and ModifiedDate
I am trying to abstract this property outside of domain object, so suppose if some one save or update a domain object he doesn't neet to set ModifiedBy and ModifiedDate property.
And we have association and collection also who has this properties
So I was using hibernate interceptor earlier to update this value to root object and it's collection and association
But I have to declare extra session factory configuration declaration in my spring context which i don't want just duplicate the decalaration of session factory and we have many mapping files
To avoid that I prefer Hibernate Events over interceptor
I am not calling any save or update method in interceptor, the reason I need use session in interceptor is identify a collection of object which is not mapped to any entity
Code:
<set name="companyAssocs" table="INV_COMPANY_TYPE_ASSN" lazy="false" fetch="join">
<key column="COMPANY_ID" not-null="true"/>
<composite-element class="com.liquid.ingest.domain.company.CompanyAssociation">
<property name="companyRoleCode" column="COMPANY_TYPE_CODE" type="java.lang.String" />
&AbstractDomainObject;
</composite-element>
</set>
B'cos this collection is never caught in intercepted or any events, but hibernate generate proper insert and update sql when I add or update object in this collection
So I did some hack not sure , it is correct way to identify collection which is not mapped.
Code:
if (types[i].isCollectionType()) {
Field field = getField(object.getClass(), properties[i]);
field.setAccessible(true);
Object object2 = (Object)field.get(object);
String role = object.getClass().getName()+"."+field.getName();
CollectionPersister persister = implr.getCollectionPersister(role);
if (persister instanceof BasicCollectionPersister) {
handleCollectionInsert(object2, who, when);
}
}