Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.1.2
-
Fix Version/s: 1.3.4
-
Component/s: Persistence, Plugins
-
Labels:None
-
Patch Submitted:Yes
Description
When trying to create a plugin for Hibernate Envers, I had issues finding the correct way to plug the hibernate event listeners in the SessionFactory.
The solution usually found on the web involves mucking with the SessionFactory after it is built to add more event listeners.
This works quite often but not with envers because its event listener implements Initializable and thus must be set on the configuration object.
I have seen the related issue GRAILS-4651 but an Interceptor is not enough for envers.
There is also GRAILS-5453, but my goal was to simplify the addition of events in a plugin not directly in the application. However I may look at creating a patch for GRAILS-5453 also.
Attached is a patch against 1.1.2 (and a new file to add in grails/src/persistence/org/codehaus/groovy/grails/orm/hibernate)
With this patch applied I can do this in a plugin :
def doWithSpring = {
auditListener(AuditEventListener)
hibernateEventListeners(HibernateEventListeners) {
listenerMap = ['post-insert':auditListener,
'post-update':auditListener,
'post-delete':auditListener,
'pre-collection-update':auditListener,
'pre-collection-remove':auditListener,
'post-collection-recreate':auditListener]
}
}
Issue Links
- is related to
-
GPAUDITLOGGING-6
beforeDelete, afterInsert, afterUpdate GORM event handlers not firing
-
-
GPAUDITLOGGING-15
Integration tests with auditable domain class do not observe test transaction boundary
-
Is there a chance that the patch might be accepted if it was updated to the latest grails version ?