Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes Call Transactional Remote Session Bean From Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Call Transactional Remote Session Bean From Spring " Watch "Call Transactional Remote Session Bean From Spring " New topic
Author

Call Transactional Remote Session Bean From Spring

Vish Shukla
Ranch Hand

Joined: Oct 12, 2008
Posts: 111
I have deployed one transactional remote session bean at server B, which should be executed in caller's transaction context. I am calling this remote session bean from my spring bean, where JTA transaction is already started(TransactionManager is injected from JBossAS). I am doing some database operation in my spring class first and then calling remote session bean with transaction active.

I am getting EjbTransactionRequiredException when method with MANDATORY transaction attribute is called in remote session bean. I doubt that whether transaction context from Spring can be propagated to remote session bean? If this is possible, then what might be going wrong in my case.

I can post code snippets or configuration if required.

Thanks & Regards,
Vishal S Shukla (SCJP 93%, SCWCD 94%, SCBCD 100%)
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9327
    
110

Can you post the entire exception stacktrace and the relevant code where the injection happens and which starts the transaction? Which version of JBoss AS is this?

[My Blog] [JavaRanch Journal]
Vish Shukla
Ranch Hand

Joined: Oct 12, 2008
Posts: 111
Hi Jaikiran,

I am using JBoss 5.0.1 GA release. When I am calling remote session bean residing in the same server instance, it works perfectly fine but not getting following stack trace when remote session bean is deployed in separate server instance.

Stacktrace :


Configurations for TransactionManager & Datasource


UserServiceImpl class :


Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9327
    
110

When I am calling remote session bean residing in the same server instance, it works perfectly fine but getting following stack trace when remote session bean is deployed in separate server instance.


See this http://www.coderanch.com/t/513513/JBoss/JBOSS-Distributed-Transactions
Vish Shukla
Ranch Hand

Joined: Oct 12, 2008
Posts: 111
Thanks for that link Jaikiran. As far as what I understand from that link is, that example looks up for UserTransaction instance from target ejb server & then controls life cycle of that transaction. I have not tried it that way.

What I exactly intent to achieve is I want to seamlessly have distributed transaction achieved i.e. container should be managing distributed transaction. As shown in the example in previous post, when save() method shown in the snippet is called, spring looks up java:/TransactionManager from local Jboss server(site 1) & transaction is started, it then delegates call to userDao.save() method in remote session bean at Jboss server(site2). I want that in this call, active transaction should be propagated to site 2. Is it possible to achieve?
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 507
Hello,
Have you tried using some other Datasource provider(The one configured using the Driver provided by Database you are using). As you are using a Commons DBCP pool, AFAIK it is the basic implementation of connection pool and datasource. May be you can check with the documentation of DBCP whether this connection can take part in distributed transacation.

Regards,
Amit
Vish Shukla
Ranch Hand

Joined: Oct 12, 2008
Posts: 111
Hi Amit,

I have also tried it by injecting MySQL's XA datasource as well as local datasource configured in jboss but got the same result.
Lingan Rajan
Ranch Hand

Joined: Jan 26, 2011
Posts: 30
Vish
I had a similar issue when communicating across Websphere Servers of different versions.
To get it working I had to turn off Transaction Authorization Coordination. Though this sounds like some thing wrong that is what is recommened by IBM.
So you might have something like this to be configured in Jboss.
See if this helps
http://community.jboss.org/message/106266
Vish Shukla
Ranch Hand

Joined: Oct 12, 2008
Posts: 111
Hi Lingan,

I think that discussion refers to quite older jboss version. I guess JBoss 5.0 supports 2+ jvms & includes arjuna products.

Just want to add one more isolation if someone can give inputs from that. I tried to call that same remote ejb(site 2) from other EJB located at site 1. But getting the same exception. So spring & its injections are not in the picture now. Just I want to have transaction propagation between two remotely located ejbs. I think it is quite common scenario in ejb environment. Eagerly looking for some help.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9327
    
110

I thought the wiki, I pointed to earlier, already has these details http://community.jboss.org/wiki/TransactionPropagationwithJBoss
Vish Shukla
Ranch Hand

Joined: Oct 12, 2008
Posts: 111
Hi Jaikiran,

sorry but I am getting totally confused.

Here are the queries and observations I have:

  • http://community.jboss.org/wiki/TransactionPropagationwithJBoss says :
    JBoss supports the first 2 cases via "ClientUserTransactionService" which is described in the AS user guide (see http://docs.jboss.org/jbossas/jboss4guide/r5/html/ch4.chapt.html):

    The ClientUserTransactionService MBean publishes a UserTransaction implementation under the JNDI name UserTransaction.

    so it means I need to use BMT to achieve this right?? what if I am using CMT, just like what is shown in the example in the discussion, using java:TransactionManager


  • The Default Transaction Manager :
    While it does support propagating transaction contexts with remote calls, it does not support propagating transaction contexts to other virtual machines, so all transactional work must be done in the same virtual machine as the JBoss server.


    I am not able to get what this quote says.


  • Transaction Propagation :
    If transaction contexts are to be propagated with RMI/JRMP calls, the transaction manager must also implement two simple interfaces for the import and export of transaction propagation contexts (TPCs). The interfaces are TransactionPropagationContextImporter, and TransactionPropagationContextFactory, both in the org.jboss.tm package.

    These interfaces and their JNDI locations are:

    The javax.transaction.TransactionManager interface is used by the application server to manage transactions on behalf of the transactional objects that use container managed transactions. It must be bound under the JNDI name java:/TransactionManager.

    The TransactionPropagationContextFactory interface is called by JBoss whenever a transaction propagation context is needed for transporting a transaction with a remote method call. It must be bound under the JNDI name java:/TransactionPropagationContextImporter.

    The TransactionPropagationContextImporter interface is called by JBoss whenever a transaction propagation context from an incoming remote method invocation has to be converted to a transaction that can be used within the receiving JBoss server VM.

    so that JBoss' implementation of TransactionManager got by java:/TransactionManager doesn't implement TransactionPropagationContextImporter & TransactionPropagationContextFactory interfaces?? what things should I do to have CMT, transaction propagation across remote calls & 2 phase commit?


  • When studying EJB specs, I thought distributed transaction propagation across remote calls should be seamlessly achieved, without putting much efforts in system level details.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Call Transactional Remote Session Bean From Spring
     
    Similar Threads
    SessionSynchronization for stateful CMT beans - reloaded
    Reentrant okay in BDOM?
    Transaction Propagation Question ??
    long post IBM.158
    Where are my BeanTransactions going to in JBoss?