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

  • No transaction is in progress

    Hi, English is not my main language, so I hope i write this correctly.
    I got an Spring 3 application and I'm trying to persist and object, but i always get the 'No transaction is in progress' error, and after reading many post in this forum I still not managed to get it working, my files are as follows:

    applicationContext.xml
    PHP Code:
    <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd   http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

        <context:property-placeholder location="classpath*:META-INF/spring/*.properties" />

        <context:spring-configured />

        <context:component-scan base-package="com.dynamica" />

        <bean class="org.apache.commons.dbcp.BasicDataSource"
            destroy-method="close" id="dataSource">
            <property name="driverClassName" value="${database.driverClassName}" />
            <property name="url" value="${database.url}" />
            <property name="username" value="${database.username}" />
            <property name="password" value="${database.password}" />
        </bean>

        <bean
            class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
            id="entityManagerFactory">
            <property name="dataSource" ref="dataSource" />
        </bean>

        <bean class="org.springframework.orm.jpa.JpaTransactionManager"
            id="transactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>

        <tx:annotation-driven mode="aspectj"
            transaction-manager="transactionManager" proxy-target-class="false" />
    </beans>
    DataConnections.java
    PHP Code:
    package com.dynamica.database;

    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;

    import org.springframework.beans.factory.annotation.Configurable;

    @
    Configurable
    public class DataConnections {

        public static final 
    EntityManager mySqlEntityManager() {
            
    EntityManager em = new DataConnections().entityManager;
            if (
    em == null)
                throw new 
    IllegalStateException(
                        
    "no se encontro o no se instanció el Entity manager de MySQL (En el XML))");
            return 
    em;
        }

        @
    PersistenceContext
        transient EntityManager entityManager
    ;


    AtributoCapturadoDAO
    PHP Code:
    package com.dynamica.database.dao.dbDynamica.webDynamica;

    @
    Configurable
    public class AtributoCapturadoDAO {
        
        @
    Transactional(propagation Propagation.REQUIRES_NEW)
        public static 
    void guarda(AtributoCapturado atributo) {
            
    DataConnections.mySqlEntityManager().persist(atributo);
            
    DataConnections.mySqlEntityManager().flush();
        }

    And the stack trace i get after the flush
    PHP Code:
    no transaction is in progressnested exception is javax.persistence.TransactionRequiredExceptionno transaction is in progress
    org
    .springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:307)
    org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc$afterThrowing$org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspect$1$18a1ac9(JpaExceptionTranslatorAspect.aj:15)
    com.dynamica.database.dao.dbDynamica.webDynamica.AtributoCapturadoDAO.guarda(AtributoCapturadoDAO.java:69)
    com.dynamica.database.model.dbDynamica.árbolesWeb.ColeccionDeDatosPendientes.guardar(ColeccionDeDatosPendientes.java:87)
    com.dynamica.web.global.controllers.CédulaController.editCédulaPost(CédulaController.java:61)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:574)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:640)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195)
    org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159)
    org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
    org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
    org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:417)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:68)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:379)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    java.lang.Thread.run(Thread.java:619
    What part I'm doing wrong?, I can't understand where is the problem

  • #2
    I see that no body responded, do I need to provide more information?
    Or there is something I'm missing?

    Comment


    • #3
      Im w8ing too Elaugus, cuz i have the same problem, I read some notes, try to take off the flush method.. this didnt work for me..
      So.. I'll wait too :/

      Comment


      • #4
        Sry, this work for me, didnt work when i use @Scope("view"), but I still use ".flush()" on my EntityManager injected..
        Is it wrong?
        Elaugus, my save method
        Code:
        @Repository
        public class GenericDao<T extends Serializable> implements Serializable {
        
        	
        
        	@PersistenceContext
        	protected EntityManager entityManager;
        
                @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
        	public void save(GenericModel entity) {
        		GenericModel genericModel = (GenericModel) entity;
        		if (genericModel.getDataCadastrado() == null) {
        			genericModel.setDataCadastrado(new Date());
        		}
        		if (genericModel.getCadastradoPor() == null) {
        			genericModel.setCadastradoPor("User");
        		}
        		if (genericModel.getId() == null || genericModel.getId() == 0) {
        			this.entityManager.persist(genericModel);
        		} else {
        			this.entityManager.merge(genericModel);
        		}
        		this.entityManager.flush();
        	}
        and my AppContext
        Code:
        <context:annotation-config />
        
        	<context:component-scan base-package="tc.*" />
        	
        	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        	        <property name="persistenceUnitName" value="mywebPU" />
        	</bean>
        	
        	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        		<property name="entityManagerFactory" ref="entityManagerFactory" />
        	</bean>
        
        	<tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" />
        
        	<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
        		<property name="scopes">
        			<map>
        				<entry key="view">
        					<bean class="tc.scopes.ViewScope" />
        				</entry>
        			</map>
        		</property>
        	</bean>
        .. <context:annotation-config /> automatically includes this PersistenceAnnotationBeanPostProcessor?
        This works on @Scope("session") someone have a @transactional implemented on view scope?

        Comment

        Working...
        X