In the application I need to built in validation rule framework.
The requirement is that:
- rule has to be checked when main object is deleted/created/updates;
- rule has to be checked when dependent object is deleted/created/updates (depended means in collection);
Choices:
1. Lifecycle interface
Problem: on Update works in strange why, it isn't fired when 'update' goes to db, don't know when it is fired.
Descision: Skip it.
2. Interceptor
The same as in 1.
3. New and preffered is Event.
preInsert, preUpdate, preDelete works like a charm.
Only problem is that when throwing the exception (when rule is broken) it generates ugly JBoss log:
15:23:26,411 ERROR [LogInterceptor] TransactionRolledbackLocalException in method: public abstract java.lang.Long xxx.MyObject.updateObject(dto) throws java.lang.Exception, causedBy:
org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=tbech-c/17, BranchQual=, localId=17] status=STATUS_NO_TRANSACTION; - nested throwable: (xxx.MyRuleException)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:354)
at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:486)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:346)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
Is there any way to get rid of this log, when RuleException is thrown, but to have log in all other cases? Or different kind of exception should be thrown from event?
And, generaly, is my approach of using events for rule validation correct or there is other better way to implement it,
|