2 Replies Latest reply on Mar 26, 2008 4:03 AM by springfans

    no transaction is in progress exception

    springfans

      I'm using Spring 2.5, Hibernate, JPA and WLS9.2, and I'm having some problems using the @Service annotation. I have a service implementation class annotated with @Service, the service class has a method called saveUser. Inside the saveUser method I do jpaTemplate.persists and jpaTemplate.flush . When flush is called, "InvalidDataAccessApiUsageException: no transaction is in progress" gets thrown.

      Here's the stack trace:
      --------------------------

      严�: org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
      javax.faces.el.EvaluationException: org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
       at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
       at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
       at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
       at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
       at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
       at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
       at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
       at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      ... 37 more
      Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
       at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:294)
       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:585)
       at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:346)
       at $Proxy112.flush(Unknown Source)
       at org.springframework.orm.jpa.JpaTemplate$8.doInJpa(JpaTemplate.java:283)
       at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:185)
       ... 76 more
      

      /WEB-INF/components.xml:
      <core:manager conversation-timeout="120000" concurrent-request-timeout="500" conversation-id-parameter="cid" />
       <core:init transaction-management-enabled="true" debug="true" />
       <transaction:no-transaction />
       <spring:context-loader />

      /WEB-INF/applicationContext.xml
      <jee:jndi-lookup id="fw.defaultDataSource" jndi-name="jdbc/crm" />
      <bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager" />
      <tx:annotation-driven transaction-manager="transactionManager" />
      <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"></bean>
      <bean id="fw.jpaTemplate" class="org.springframework.orm.jpa..JpaTemplate">
       <property name="entityManagerFactory" ref="fw.defaultEMF" />
       </bean>
      <bean id="fw.defaultEMF" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
       <property name="dataSource" ref="fw.defaultDataSource" />
       <property name="jpaVendorAdapter">
       <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
       <property name="database" value="ORACLE" />
       <property name="showSql" value="true" />
       </bean>
       </property>
       <property name="loadTimeWeaver">
       <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
       </property>
       <property name="persistenceUnitName" value="fw.defaultPersistenceUnit" />
       </bean>

      RegisterAction.java
      @In("#{userService}")
       private UserService userService;
      public void register() {
      userService.createUser(user);
      }
      }

      UserService.java
      @Autowired
      @Qualifier("fw.jpaTemplate")
      org.springframework.orm.jpa.JpaTemplate jpaTemplate;
      
      @Transactional
       public void createUser(final User user) throws ValidationException {
      jpaTemplate.persist(user);
      jpaTemplate.flush();
      }
      

      User.java
      @Entity
      @Name("user")
      @Scope(SESSION)
      @Table(name="Customer")
      public class User implements Serializable
      {....}
      


        • 1. Re: no transaction is in progress exception
          springfans

          SORRY:

          /WEB-INF/components.xml

          <core:manager conversation-timeout="120000" concurrent-request-timeout="500" conversation-id-parameter="cid" />
           <core:init transaction-management-enabled="false" debug="true" />
           <transaction:no-transaction />
           <spring:context-loader />


          Help me!

          • 2. Re: no transaction is in progress exception
            springfans

            SORRY:

            /WEB-INF/components.xml

            <core:manager conversation-timeout="120000" concurrent-request-timeout="500" conversation-id-parameter="cid" />
             <core:init transaction-management-enabled="false" debug="true" />
             <transaction:no-transaction />
             <spring:context-loader />


            Help me!