title: Cannot call commit when using distributed transactions (EJB, Spring, Hibernate and Weblogic)
body: <p>I'm creating an EJB in an existent application (running in weblogic 12), to call a method in a Spring component, that calls a DAO annotated as @Transactional to modify a record in the database. The problem is that after call the DAO method I received the following exception:</p>
  
  <pre><code>Caused by: org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: JDBC commit failed
      at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:661)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:475)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:270)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
      at org.newton.imp.storage.dao.AresDaoImpl$$EnhancerByCGLIB$$f33ba225.saveAresStatus(&lt;generated&gt;)
      at org.newton.imp.storage.managers.ares.AresManagerImpl.uploadDocument(AresManagerImpl.java:166)
      at org.newton.imp.storage.managers.ares.AresManagerImpl.registerDocument(AresManagerImpl.java:326)
      at org.newton.imp.storage.managers.ares.AresManagerImpl$$FastClassByCGLIB$$d04be4e1.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:627)
      at org.newton.imp.storage.managers.ares.AresManagerImpl$$EnhancerByCGLIB$$ec954055.registerDocument(&lt;generated&gt;)
      at org.newton.business.ejb.NewtonAresManagerBean.registerDocument(NewtonAresManagerBean.java:80)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
      at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
      at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
      at com.oracle.pitchfork.intercept.MethodInvocationInvocationContext.proceed(MethodInvocationInvocationContext.java:103)
      at com.oracle.pitchfork.intercept.JeeInterceptorInterceptor.invoke(JeeInterceptorInterceptor.java:115)
      at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
      at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
      at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(Unknown Source)
      at $Proxy707.registerDocument(Unknown Source)
      at org.newton.business.ejb.NewtonAresManagerBean_po5cm8_NewtonAresManagerRemoteImpl.__WL_invoke(Unknown Source)
      at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:32)
      at org.newton.business.ejb.NewtonAresManagerBean_po5cm8_NewtonAresManagerRemoteImpl.registerDocument(Unknown Source)
      at org.newton.business.ejb.NewtonAresManagerBean_po5cm8_NewtonAresManagerRemoteImpl_WLSkel.invoke(Unknown Source)
      at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:201)
      at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:461)
      at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:272)
      at org.newton.business.ejb.NewtonAresManagerBean_po5cm8_NewtonAresManagerRemoteImpl_1211_WLStub.registerDocument(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:84)
      ... 21 more
  
      Caused by: org.hibernate.TransactionException: JDBC commit failed
          at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:161)
          at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:657)
          ... 64 more
  
      Caused by: java.sql.SQLException: Cannot call commit when using distributed transactions
          at weblogic.jdbc.wrapper.JTAConnection.commit(JTAConnection.java:365)
          at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:170)
          at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:146)
          ... 65 more
  </code></pre>
  
  <p>My configuration/ classes are:</p>
  
  <p>EJB:</p>
  
  <pre><code>@Stateless(name = "NewtonAresManagerBean", mappedName = "NewtonAresManagerRemote")
  @Interceptors(SpringBeanAutowiringInterceptor.class)
  public class NewtonAresManagerBean implements NewtonAresManagerRemote {   
      protected static final Logger LOG = LoggerFactory.getLogger(NewtonAresManagerBean.class);
  
      @Autowired
      private AresManager aresManager;
  
  
      @Override
      public String registerDocument(final FileStorage fileStorage, final ProjectInformationTO project, final AresTypes aresType, final Long reportingPeriod, final AresProcessingType processingType) throws CommonNewtonException, NoInternalEntityFoundException, NoExternalEntityFoundException {       
  
          Object status = aresManager.registerDocument(aresType, fileStorage, project, reportingPeriod, null, null, null, processingType);
      }
  }
  </code></pre>
  
  <p>Spring component:</p>
  
  <pre><code>@Component("aresManager")
  public class AresManagerImpl implements AresManager {
       @Override
      public Object registerDocument(final AresTypes aresType, final FileStorage fileStore, final ProjectInformationTO projectInformation,
              final Integer periodNumber, final Long submissionId, final String participantId, final Long participantNumber,
              final AresProcessingType aresProcessingType)
              throws CommonBusinessException {
  
      Object status = new Status();
      final Object uploadBean = uploadDocument(aresType, status, fileStore);
          return uploadBean;
      }
  
  
      @Override
      public Object uploadDocument(final AresTypes aresType, final AresStatus status, final FileStorage fileStore) {
          try {
              final Object responseBean = getCommonHelper().uploadFile(aresType, fileStore);
  
              getCommonHelper().getAresDao().saveAresStatus(status);
  
              return responseBean;
          } catch (final Exception e) {            
          } 
          return null;
      }
  }
  </code></pre>
  
  <p>DAO:</p>
  
  <pre><code>@Repository("aresDao")
  @Transactional(propagation = Propagation.REQUIRED)
  public class AresDaoImpl implements AresDao {
      @Autowired
      @Qualifier("mySessionFactory")
      private SessionFactory mySessionFactory;
  
      @Override
      public void saveAresStatus(final AresStatus status) {
          try {
              mySessionFactory.getSession().saveOrUpdate(status) 
          } catch (final Exception e) {
          }
  
      }
  }
  </code></pre>
  
  <p>Configuration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:aop="http://www.springframework.org/schema/aop"
         xmlns:p="http://www.springframework.org/schema/p"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
             http://www.springframework.org/schema/context
             http://www.springframework.org/schema/context/spring-context-3.1.xsd
             http://www.springframework.org/schema/tx
             http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
             http://www.springframework.org/schema/aop
             http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"
      default-autowire="byName"&gt;
  
      &lt;!-- Hibernate SessionFactory --&gt;
  
      &lt;bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
          p:dataSource-ref="fpX_business_datasource"&gt;
  
          &lt;property name="hibernateProperties"&gt;
              &lt;value&gt;
                  hibernate.hbm2ddl.auto=validate
  
                  hibernate.generate_statistics=true
  
                  hibernate.show_sql=false
                  hibernate.format_sql=true
                  hibernate.use_sql_comments=false
  
                  hibernate.max_fetch_depth=1
  
                  hibernate.transaction.auto_close_session=false
  
                  hibernate.use_identifier_rollback=true
  
                  hibernate.jdbc.batch_size=5
  
                  hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
          hibernate.transaction.factory_class=org.transaction.JDBCTransactionFactory
                  hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
                  hibernate.cache.use_second_level_cache=false
                  hibernate.cache.use_query_cache=false
                  hibernate.cache.use_minimal_puts=false
              &lt;/value&gt;
          &lt;/property&gt;        
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"&gt;
          &lt;property name="transactionManagerName" value="javax.transaction.TransactionManager" /&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>I'll really appreciate if someone can give a clue on how to solve this error.</p>