Announcement Announcement Module
No announcement yet.
Spring, Glassfish, Remote EJB and JTA Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring, Glassfish, Remote EJB and JTA


    I have simple main-method where I try to call a method on a remote EJB bean which requires an EJB transaction. I've set up an JtaTransactionManager where I change the jndi-environment to the IP-address of the machine that runs Glassfish (SGCS). After that I fetch the remote EJB bean from the same Glassfish machine with an helper class (BeanUtil). I then call JtaTransactionManger.getTransaction(def) and then I call the method on the remote bean which requires an transaction. However when I call the method on the remote bean I can see in the log that an transaction is created but after that it just hangs. See the code below.

    public class TransactionManager extends JtaTransactionManager {
        private static Logger logger = Logger.getLogger(TransactionManager.class);
        private String deployType;
        public void setDeployType(String deploymentType) {
            this.deployType = deploymentType;
        public void afterPropertiesSet() throws TransactionSystemException {
            if("dev".equals(deployType)) {
                Properties ENV = new Properties();
                ENV.put("org.omg.CORBA.ORBInitialHost", "");
                ENV.put("org.omg.CORBA.ORBInitialPort", "33700");
        public static void main(String[] args) {
            ChangeRetrieverRemote crr = BeanUtil.jndiLookup(ChangeRetrieverRemote.class, ChangeRetrieverRemote.JNDI_NAME);
            TransactionManager tx = new TransactionManager();
            TransactionDefinition def = new TransactionDefinition() {
                public boolean isReadOnly() {
                    return true;
                public int getTimeout() {
                    return 0;
                public int getPropagationBehavior() {
                    return PROPAGATION_REQUIRED;
                public String getName() {
                    return "apa";
                public int getIsolationLevel() {
                    return ISOLATION_DEFAULT;
            logger.debug("getting transaction");
            TransactionStatus status = tx.getTransaction(def);
            logger.debug("LATEST VERSION: " + crr.getLatestChange(new DataRef("tracked", "epgcs", "programUpdate")));
    Console log:
    17:57:31,830 DEBUG JndiTemplate:151 - Looking up JNDI object with name [java:comp/UserTransaction]
    17:57:32,038 DEBUG TransactionManager:676 - JTA UserTransaction found at default JNDI location [java:comp/UserTransaction]
    17:57:32,038 DEBUG JndiTemplate:151 - Looking up JNDI object with name [java:comp/TransactionManager]
    17:57:32,041 DEBUG TransactionManager:717 - No JTA TransactionManager found at fallback JNDI location [java:comp/TransactionManager]
    javax.naming.NameNotFoundException: No object bound for java:comp/TransactionManager [Root exception is java.lang.NullPointerException]
    	at com.sun.enterprise.naming.SerialContext.lookup(
    	at javax.naming.InitialContext.lookup(
    	at org.springframework.jndi.JndiTemplate$1.doInContext(
    	at org.springframework.jndi.JndiTemplate.execute(
    	at org.springframework.jndi.JndiTemplate.lookup(
    	at org.springframework.jndi.JndiTemplate.lookup(
    	at org.springframework.transaction.jta.JtaTransactionManager.findTransactionManager(
    	at org.springframework.transaction.jta.JtaTransactionManager.initUserTransactionAndTransactionManager(
    	at org.springframework.transaction.jta.JtaTransactionManager.afterPropertiesSet(
    	at se.dreampark.transactionmanager.TransactionManager.afterPropertiesSet(
    	at se.dreampark.transactionmanager.TransactionManager.main(
    Caused by: java.lang.NullPointerException
    	... 11 more
    17:57:32,042 DEBUG JndiTemplate:151 - Looking up JNDI object with name [java:appserver/TransactionManager]
    17:57:32,043 DEBUG TransactionManager:711 - JTA TransactionManager found at fallback JNDI location [java:appserver/TransactionManager]
    17:57:32,044  INFO TransactionManager:488 - Using JTA UserTransaction: [email protected]
    17:57:32,044  INFO TransactionManager:499 - Using JTA TransactionManager: [email protected]
    17:57:32,046 DEBUG JndiTemplate:151 - Looking up JNDI object with name [java:comp/TransactionSynchronizationRegistry]
    17:57:32,047 DEBUG TransactionManager:752 - JTA TransactionSynchronizationRegistry found at default JNDI location [java:comp/TransactionSynchronizationRegistry]
    17:57:32,048  INFO TransactionManager:529 - Using JTA TransactionSynchronizationRegistry: com.sun.enterprise.distributedtx.TransactionSynchronizationRegist[email protected]
    17:57:32,048 DEBUG TransactionManager:69 - getting transaction
    17:57:32,051 DEBUG TransactionManager:371 - Creating new transaction with name [apa]: [email protected]
    As you can see the two last log statements are missing. Any ideas?

    Just as a side-note, the real problem is that I'm trying to get this to work together with Spring. I get the exact same problem when I'm running spring, using annotations to activate the transaction handling. Right now however, I'm concentrating on getting it to work in my main-method before I try to solve the problem in spring.

    Thanks in advance