[jboss-user] [EJB 3.0] - EJB3 Session Facade TransactionRequiredException

mjrother do-not-reply at jboss.com
Thu Jul 20 13:09:53 EDT 2006

I was wondering the best way the handle the following with EJB3. I have a EJB3 Session Bean which acts as a facade for business activities. In a method, I want to check for existing records and report the error prior to attempting to persist an business object. I am looking for the existance of a database record (say user table with a username field). If the record exists, I return an error that already exists. When I try to find the user record, if not there a EJB3TransactionRollbackException is raised with the cause a NoResultException. I trap the exception but when I try to continue and persist the new record, I get a TransactionRequiredException.

User user = null;
// pseudocode
try {
   user = em.findById(username);
   // throw already exists exception
catch (RuntimeException) ex) {
   // test cause and try to continue... desired path

if (user == null) {
    User user = new User(username);

It appears that once a exception is raised, you cannot continue. How can I perform the database check and still continue? 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3959641#3959641

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3959641

More information about the jboss-user mailing list