users@glassfish.java.net

@Schedule and @TransactionAttribute(NEVER) not compatible

From: <forums_at_java.net>
Date: Tue, 4 Sep 2012 09:15:29 -0500 (CDT)

Hello, I think that the @TransactionAttribute annotation is not taken into
account when there is an @Schedule annotation on the same method (a
transaction is created). Am I true? What the correct way of doing? Thanks for
your help, GĂ©rald Detailed problem: I have 2 EJBs which shouldn't have any
transaction. The first one is called periodically: @Singleton @Startup public
class FrontSingleton { private static final Logger
LOGGER=Logger.getLogger(FrontSingleton.class.getName()); @EJB private
BackStateless backStateless; @Schedule(hour="*", minute="*/1")
@TransactionAttribute(TransactionAttributeType.NEVER) public void
runPeriodicallyWithoutTx() { LOGGER.info("Running periodically");
backStateless.runWithOutTx(); } } The second one doesn't support
transactions: @Stateless public class BackStateless { private static final
Logger LOGGER=Logger.getLogger(BackStateless.class.getName());
@TransactionAttribute(TransactionAttributeType.NEVER) public void
runWithOutTx() { LOGGER.info("Running without transaction"); } } Each time
the runPeriodicallyWithoutTx method is ran, I get an exception: INFO: Running
periodically ATTENTION: A system exception occurred during an invocation on
EJB BackStateless method public void
com.mycompany.test.glassfish.BackStateless.runWithOutTx()
javax.ejb.EJBException: EJB cannot be invoked in global transaction at
com.sun.ejb.containers.BaseContainer.preInvokeTx(BaseContainer.java:4602) at
com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1910) at
com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
at
com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy177.runWithOutTx(Unknown Source) at
com.mycompany.test.glassfish.__EJB31_Generated__BackStateless__Intf____Bean__.runWithOutTx(Unknown
Source) at
com.mycompany.test.glassfish.FrontSingleton.runPeriodicallyWithoutTx(FrontSingleton.java:25)
I tested on GlassFish 3.0.1 and 3.1.1.

--
[Message sent by forum member 'gquintana']
View Post: http://forums.java.net/node/889830