[JBoss Seam] - Exception Handling (w/ interceptor)
by texan
I created a "global" interceptor (below) to simply catch unhandled exceptions and send the user to a nice error screen. I put it in ejb-jar.xml in front of the Seam interceptor, since Seam itself is source of Exceptions (no doubt because of my abuse of the framework).
My concern was by catching Exception and not rethrowing it, I was bypassing the EJB container's rollback. Sure enough, that's true. That is, the user sees the error page, but the transaction completes normally.
My question is this: what is a good pattern for this? Should my transactional methods (save, delete) always catch exceptions, roll back the transaction manually, then rethrow them so it goes to my error page? Is there a way to send the user to an error page without bypassing the EJB transaction processing?
BTW, I tried using the new @Interceptor(type=CLIENT) tag to see if I could move my exception handling outside of the EJB calls. This required removing the entry from ejb-jar.xml and adding an @Interceptors(MyExceptionInterceptor.class) to the top of my session bean. Unfortunately, that resulted in the user seeing the Seam debug page, which is helpful but not pretty. Obviously, I don't fully understand the use of the @Interceptor tag...
| public class MyExceptionInterceptor {
|
| @AroundInvoke
| public Object handleException(InvocationContext invocation) throws Exception {
|
| try {
| return invocation.proceed();
| }
| catch (Exception t) {
| return "error";
| }
| }
|
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3971412#3971412
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3971412
19 years, 7 months
[Persistence, JBoss/CMP, Hibernate, Database] - TransactionException: could not register synchronization roo
by holmes.j
So we've just decided to jump on the Hibernate/EJB3 bandwagon. We were using EJB2.1 before. I'm not really familiar with much of that as I just joined, but it looks nasty.
Anyways, I've got Hibernate working in our test environment, following the CaveatEmptor example rather closely.
However, once deployed to JBoss, it's just not working. I'm trying to use JTA to manage the transactions, but something somewhere isn't making the connection it needs too.
In our SessionBean, once the Dao is called, it decides it wants to throw an Exception with the message: "load is not valid without active transaction". I'm betting it's root is a NPE, but I haven't navigated that far deep.
To make sure it wasn't the SessionBean that was causing the problem, I just threw a line in a jsp to get the Dao. That comes back with a org.hibernate.TransactionException: could not register synchronization, who's root cause is a NPE from the transaction in JTATransaction.registerSynchronization() (line 306)
So, I don't really know how to get this stuff to work. Below is my hibernate.properties file.
| hibernate.c3p0.min_size=5
| hibernate.c3p0.max_size=20
| hibernate.c3p0.timeout=1800
| hibernate.c3p0.max_statements=50
|
| hibernate.current_session_context_class=jta
| hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory
| hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup
| hibernate.transaction.flush_before_completion=true
| hibernate.transaction.auto_close_session=true
|
| hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
| hibernate.show_sql=true
| hibernate.format_sql=true
| hibernate.generate_statistics=true
|
| hibernate.bytecode.use_reflection_optimizer=false
| hibernate.bytecode.provider=javassist
|
Any idea on what else I have to do to get transactions to work with JTA?
Thanks,
Jason
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3971408#3971408
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3971408
19 years, 7 months