Jboss 7.1.1 Transactions, Cascaded EJB Methods

I have two stateless SessionBeans. My client (JSF2 application) calls the (saveOrderCompletion) method in the first EJB (CompletionFacade), which calls another method (processRequest) in the second EJB (ContactFacade) to send the message to the queue through the JMS.

At the end of the first method called, I throw a RuntimException to see how JBoss behaves. This must be done in one transaction, so the transaction must roll back so that no message is sent to the queue.

I double-checked this on a weblogic server that shows the exact behavior. My question is why does JBoss not roll back the whole transaction? Did I miss something...

The entity is not saved, but the message is still sent to the queue.

I am using jboss 7.1.1, the application is deployed as an EAR

Here is my beans session ...

/** * Session Bean implementation class CompletionFacade */ @Stateless public class CompletionFacade implements CompletionFacadeRemote, CompletionFacadeLocal { @PersistenceContext(unitName="my_test") private EntityManager entityManager; @EJB ContactFacadeLocal contactFacade; ..... @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public OrderCompletion saveOrderCompletion(OrderCompletion orderCompletion) throws TestBusinessException { try { ...do some stuff on entity //persist to get id entityManager.persist(orderCompletion); //finally send email contactFacade.processRequest(orderCompletion,partner); if (0 == 0) throw new RuntimeException("Test RuntimeException "); } catch (TestGenericException re) { throw new TestBusinessException("Could not print orderCompletion: " ,re); } catch (DocumentException e) { throw new TestBusinessException("Could not print orderCompletion: " ,e); } return orderCompletion; } } 

and the second facade:

 @Stateless public class ContactFacade implements ContactFacadeRemote, ContactFacadeLocal { .... /* * actually create message */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void processRequest(Object request, SmtpPartner partner) throws TestGenericException { if (logger.isDebugEnabled()) { logger.debug("Starting to process request!"); } QueueConnection connection = null; QueueSession session = null; try { ...lookup queue etc... sender.send(QUEUE, objectMessage); } catch (JMSException e) { logger.error("MS Exception:", e); } catch (NamingException e) { logger.error("Naming exception:", e); } ... } finally { try { session.close(); connection.close(); } catch (JMSException e) { logger.error("Error closing connection:", e); } } } ... } 

Any help is appreciated.

+4
source share
1 answer

You left the most important part; JMS factory connection, where you get the connection and the way you mastered this factory.

Make sure you enter this factory and use transactional. In JBoss AS 6, java: / JmsXA was transactional, and java: / ConnectionFactory was an unmanaged / non-transactional alternative. Make sure that you are using the correct one for AS 7.

+3
source

Source: https://habr.com/ru/post/1415634/


All Articles