Runtime exceptions cause transactions to role back. Checked exceptions do not. Lawrence Justin Casp wrote:
> Hello, > I'm hoping somebody out there can give me a hint on how to set up transaction > attributes for session beans that behave in the following manner. > > ImportantBean has a method, 'doImportantWork' which throws MajorException > UnimportantBean has a method 'doUnimportantWork' which throws TrivialException > > MainBean has a method 'doWork' : > > doWork() throws MajorException { > ImportantBean.doImportantWork(); > try { > UnimportantBean.doUnimportantWork(); > } catch (TrivialException t) { > //do something that doesn't matter much > } > } > > If ImportantBean's method throws an exception, I want the transaction to be > rolled back. This is easy, standard behavior- no problem. > > I want to catch the TrivialException without causing the transaction to be > rolled back for MainBean. Currently, when I catch TrivialException in my > MainBean method, the TX gets rolled back. > > I have tried setting the transaction attributes of UnimportantBean's methods > to both "NotSupported" and "RequiresNew", but both of these settings cause a > transaction timeout with JBoss. The other beans' methods are set to the > default, 'Required'. > > I thought that by setting the UnimportantBean to 'NotSupported', I would be > suspending the MainBean's transaction during this code's execution. That > way, if an exception was thrown in doUnimportantWork(), it wouldn't matter to > MainBean. Obviously, this reasoning is wrong, but I'm not sure why. I guess > having MainBean catch an exception as described above means the transaction > context is re-entered/unsuspended when the exception is caught. > > Thank you in advance for saving me from transaction ignorance. > Justin > > ------------------------------------------------------- > This SF.net email is sponsored by: SlickEdit Inc. Develop an edge. > The most comprehensive and flexible code editor you can use. > Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial. > www.slickedit.com/sourceforge > _______________________________________________ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user ------------------------------------------------------- This SF.net email is sponsored by: SlickEdit Inc. Develop an edge. The most comprehensive and flexible code editor you can use. Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial. www.slickedit.com/sourceforge _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user