just to clarify...is this the right approach to veto using event listeners?
I am looking how to veto changes using event listeners. As event listeners are more flexible than interceptors it also seemed more complicated. I began reading that they mimic the Session interface methods, so looked at extending the appropriate events for those methods which did something I wanted to veto. DefaultSaveOrUpdateEventListener and many others... Then I wasn't sure how to veto the changes anyway!
I then discovered at the end of ch12 (online reference) that the JAAS security implements the onPre...EventListeners. Although this code throws exceptions, the onPre...interface expects a boolean return value - which I found is the veto! - NB This wasn't in the documentation!! Return true to veto. Basically I think to veto all changes to the database, I need a class to implement preInsertEventListener, preUpdateEventListener, preDeleteEventListener and return true. Then I shall wire the class like the example - but each could refer to the same class implementing all the interfaces.
Code:
<listener type="pre-delete" class="org.hibernate.secure.JACCPreDeleteEventListener"/>
<listener type="pre-update" class="org.hibernate.secure.JACCPreUpdateEventListener"/>
<listener type="pre-insert" class="org.hibernate.secure.JACCPreInsertEventListener"/>
NB - note also that the 'pre-delete' names have no documentation on their mapping to the interfaces such as onPreDeleteEventListener. Although it doesn't take a genius to work out the mapping it could be a a little confusing sometimes as there is a mismatch between them in terms of numbers (eg what is post-commit-delete's listener). You can find out the names from a line in the dtd (
http://hibernate.sourceforge.net/hibern ... on-3.0.dtd), They are
(auto-flush|merge|create|delete|dirty-check|evict|
flush|flush-entity|load|load-collection|lock|refresh|
replicate|save-update|save|update|pre-load|pre-update|
pre-insert|pre-delete|post-load|post-update|post-insert|
post-delete|post-commit-update|post-commit-insert|post-commit-delete)
I'm about to give it a go - but it all seems to fit. Just thought I'd add for those wanting to try it in the new event listener way. And give other an opportunity to correct me if this is not the way to do it!
adam