Announcement Announcement Module
Collapse
No announcement yet.
problem of transactions :TransactionProxyFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem of transactions :TransactionProxyFactoryBean

    Hi,
    I have a problem with "org.springframework.transaction.interceptor.Trans actionProxyFactoryBean"
    From what I understood, this class allow to manage transactions for a service. Here is how I use it :
    Code:
    	<bean id="quickSearchManagementService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager"><ref bean="myTxManager"/></property>
            <property name="transactionAttributes">
                <props>
                    <prop key="*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
            <property name="target">
       			<bean class="org.springframework.aop.framework.ProxyFactoryBean">	
    				<property name="target"><ref bean="quickSearchManagementServiceTarget"/></property>
    				<property name="proxyInterfaces">
    					<value>com.flexcipio.clinical.service.QuickSearchManagementService</value>
    				</property>
    				<property name="interceptorNames">
    					<list>
    						<value>methodSecurityInterceptor</value>
    					</list>
    				</property>
    			</bean>    
    		</property>
        </bean>
    And here is the target implementation service class :
    Code:
    		<bean id="quickSearchManagementServiceTarget" class="com.flexcipio.clinical.service.impl.QuickSearchManagementServiceImpl">
                    <property name="sessionFactory"><ref bean="sessionFactory"/></property>
    		<property name="formDao"><ref bean="formDao"/></property>
    	</bean>
    Inside this implementation, I need a transaction that I have to commit to take into account some changes :
    Code:
    public List<Form> searchForm(String search, User user) {
                  ...............................
                  ...............................
    			Transaction tx = sessionFactory.getCurrentSession().beginTransaction();
    			List<Form> forms = formDao.findByAll();
    			for ( Form form : forms) {
    				String formName = form.getName();
    				form.setName(formName+"1");
    				formDao.update(form);
    			}
    			tx.commit();
                ..............................
                ..............................
    }
    And I get the following error :
    Code:
    org.hibernate.TransactionException: Transaction not successfully started
    	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:100)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    	at $Proxy89.searchForm(Unknown Source)
    	at com.clinical.web.controller.impl.QuickSearchManagementControllerImpl.getQuickSearch(QuickSearchManagementControllerImpl.java:101)
    	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.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473)
    	at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
    	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    I don't know what happen. Apparently, I cannot begin a transaction inside a method of my service to make update and commit this transaction so that updates are taken in account. TransactionProxyFactoryBean seems to forbid this. I don't catch anything of transactions. Can anybody explain me what I can do to use a trannsaction in a method of my service and commit it without errors. If you can explain me at the same tim a little bit about TransactionProxyFactoryBean, you are welcome. Thanks in advance.

  • #2
    <property name="target">
    <bean class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="target"><ref bean="quickSearchManagementServiceTarget"/></property>
    <property name="proxyInterfaces">
    <value>com.flexcipio.clinical.service.QuickSearchM anagementService</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>methodSecurityInterceptor</value>
    </list>
    </property>
    </bean>
    </property>




    what's this mean?

    Comment


    • #3
      Thank-you for your reply
      effectively I changed to
      Code:
      	<bean id="quickSearchManagementService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
              <property name="transactionManager"><ref bean="myTxManager"/></property>
              <property name="transactionAttributes">
                  <props>
                      <prop key="*">PROPAGATION_REQUIRED</prop>
                  </props>
              </property>
              <property name="target" ref="quickSearchManagementServiceTarget"/>
          </bean>
      And i still have the same error

      Comment


      • #4
        can you alternative PROPAGATION_REQUIRED to PROPAGATION_SUPPORTS, and try to run your application and then tell me your result?

        Comment


        • #5
          I did what you suggested And I haven't any more the error. Thanks. Can you tell me more about this issue ?

          Comment


          • #6
            you started two transactions with listForms method, and they did not do propagation properly.

            Comment

            Working...
            X