Dave Bredesen [
http://community.jboss.org/people/dbredesen] created the discussion
"calling a transactional helper method from within a non-transactional EJB
method"
To view the discussion, visit:
http://community.jboss.org/message/552004#552004
--------------------------------------------------------------
So I'm trying to call a +transactional+ helper method from within a
+non-transactional+ EJB3 service method. Since the EJB method has no transaction, a new
one cannot be created through the local call to the helper method, because there is no txn
wrapper initiated by the container.
The usual way around this is to get a handle to the local EJB instance via the
SessionContext, and call the method through the handle. So:
*@Service*
*public class MyEJB {*
* @SessionContext ctx;*
*
*
* public void myPublicButNonTransactionalMethod() {*
* ((MyEJBLocal) ctx.getEJBLocalObject()).helperMethod();*
* }*
*
*
* @TransactionAttribute(REQUIRED)*
* public void helperMethod() {*
* entityManager.persist(someObj);*
* }*
*}*
Unfortunately, this doesn't seem to work in JBoss, and the errors are silly. I have
tried 3 different approaches:
*ctx.getEJBLocalObject()*
*java.lang.IllegalStateException: NYI
*
**
**
*ctx.getEJBObject()*
*java.lang.IllegalStateException: NYI*
**
**
*ctx.getBusinessObject()*
*java.lang.IllegalStateException: Not implemented*
Isn't there any way to call the helper method to get a transaction without resorting
to an Initial Context / JNDI lookup / etc??
This is JBoss AS 5.1.0, using Hibernate.
Thanks,
--d
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/552004#552004]
Start a new discussion in EJB 3.0 at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]