Announcement Announcement Module
Collapse
No announcement yet.
No transaction is in progress; nested exception is javax.persistence.TransactionRequi Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • No transaction is in progress; nested exception is javax.persistence.TransactionRequi

    Stack: Spring 3.1, Spring JPA, Websphere 6.1, JTA, Messaging

    I have a message listener as a part of my application. The message listener consumes a message and as part of processing the message creates some entitities in the database. To create entitities it uses Entity Services which are annotated as @Transactional calling the underlying spring JPA to persist entity.
    Here is the configuration i have in the app-context.xml file used by spring

    Code:
    <context:annotation-config />
    <tx:annotation-driven/>
    <context:component-scan base-package="base.package" />
    
    <bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"
              p:allowCustomIsolationLevels="true"/>
    
    <bean id="jpaEntityManagerFactory" name="entityManagerFactory"
              class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="packagesToScan" value="package.containing.entitities"/>
            <property name="jpaDialect">
                <bean class="com.johnlewis.jec.webpim.domain.repository.HibernateExtendedJpaDialect"/>
            </property>
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="showSql" value="${hibernate.show_sql}"/>
                    <property name="databasePlatform" value="${hibernate.dialect}"/>
                </bean>
            </property>
            <property name="jpaProperties">
                <props>
                    <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</prop>
                    <!--<prop key="hibernate.transaction.flush_before_completion">true</prop>-->
                    <!--<prop key="hibernate.transaction.auto_close_session">true</prop>-->
                    <!--<prop key="hibernate.current_session_context_class">thread</prop>-->
                    <!--<prop key="javax.persistence.transactionType">JTA</prop>-->
                    <!--<prop key="hibernate.connection.release_mode">auto</prop>-->
                </props>
            </property>
        </bean>
    
        <jpa:repositories base-package="package.containing.spring.jpa.repository"/>
    
    <bean  id="messageListenerContainer"
              class="org.springframework.jms.listener.DefaultMessageListenerContainer">
            <property name="taskExecutor" ref="taskExecutor"/>
            <property name="transactionManager" ref="transactionManager"/>
            <property name="sessionTransacted" value="true"/>
            <property name="connectionFactory" ref="myConnectionFactory"/>
            <property name="destination" ref="incoming.queue"/>
            <property name="messageListener" ref="entityMessageListener"/>
        </bean>
    
    <bean id="entityMessageListener" class="my.package.name.EntityMessageListener"/>
    While trying to persist entity i am getting the following error in my logs. I have tried lots of different suggestions i could find in various forums and documentation. I would greatly appreciate if some one can provide more light or solution of the problem i am getting

    Here are the logs of my application.

    Code:
    Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
            at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:321) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:106) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58) ~[spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163) ~[spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:84) ~[spring-data-jpa-1.1.0.RELEASE.jar:na]
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at $Proxy2140.saveAndFlush(Unknown Source) ~[na:na]
            at com.johnlewis.jec.webpim.app.services.line.LineLifecycleManager.create(LineLifecycleManager.java:23) ~[common-1.1.5-SNAPSHOT.jar:na]
            at com.johnlewis.jec.webpim.app.services.line.LineLifecycleManager$$FastClassByCGLIB$$e4a29e38.invoke(<generated>) ~[cglib-2.2.jar:na]
            at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) ~[cglib-2.2.jar:na]
            at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.transaction.interceptor.TransactionInterceptor$1.doInTransaction(TransactionInterceptor.java:132) ~[spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.transaction.jta.WebSphereUowTransactionManager$UOWActionAdapter.run(WebSphereUowTransactionManager.java:337) ~[spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at com.ibm.ws.uow.UOWManagerImpl.runUnderCurrentUOW(UOWManagerImpl.java:1163) ~[com.ibm.ws.runtime_6.1.0.jar:na]
            at com.ibm.ws.uow.UOWManagerImpl.runUnderUOW(UOWManagerImpl.java:515) ~[com.ibm.ws.runtime_6.1.0.jar:na]
            at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:281) ~[spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:127) ~[spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
            at com.johnlewis.jec.webpim.app.services.line.LineLifecycleManager$$EnhancerByCGLIB$$c2fd635a.create(<generated>) ~[cglib-2.2.jar:na]
            at com.johnlewis.jec.webpim.app.services.sku.SkuLifecycleManager.createSkusForNewLine(SkuLifecycleManager.java:117) ~[common-1.1.5-SNAPSHOT.jar:na]
            at com.johnlewis.jec.webpim.app.services.sku.SkuLifecycleManager$$FastClassByCGLIB$$15675ed6.invoke(<generated>) ~[cglib-2.2.jar:na]
            at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) ~[cglib-2.2.jar:na]
Working...
X