Announcement Announcement Module
No announcement yet.
Transactions within WebFlow Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transactions within WebFlow

    hi all....

    I have an application that is not performing updates/creates. I'm utilizing Spring WebFlow and have annotated my service with the @Transactional annotation. I'm able to read data no problem. No exceptions are being thrown. I'm not using persistence-context within my flow. Looking at the logging, all the sql selects are being issued correct, but no updates/creates.

    SWF Version is 2.0.8.
    Spring Version is 2.5.6.

    If someone can point me in the right direction, it would be very helpful. here's my config:

    Service Method
        public void updateUser(String id) {
    	User user = this.find(new Integer(id));
    	java.util.Calendar loginDate = java.util.Calendar.getInstance();
    	loginDate.setTime(new java.util.Date());
    Data Access Config:

    <!-- Turn on AspectJ @Configurable support -->
    	<!-- Instructs Spring to perfrom declarative transaction management on annotated classes -->
    	<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
    	<!-- Drives transactions using local JPA APIs -->
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	<!-- Creates a EntityManagerFactory for use with the Hibernate JPA provider and a simple in-memory data source populated with test data -->
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    My web flow config (revelent part):

    <!-- Installs a listener that manages JPA persistence contexts for flows that require them -->
    	<bean id="jpaFlowExecutionListener" class="org.springframework.webflow.persistence.JpaFlowExecutionListener">
    		<constructor-arg ref="entityManagerFactory" />
    		<constructor-arg ref="transactionManager" />
    If I call entityManager.flush() from within my service method (updateUser above), an exception is thrown saying 'no transaction is in progress'.

    I also tried loading the user within my flow my making a call '<evaluate expression....result=flowScope.applicationUser'/>, then calling <evaluate expression...userService.merge(applicationUser) but no luck there either.

    any help is appreciated...


  • #2
    If there is no update and if you do a flush it throws an exception your setup is wrong... You use @Transactional make sure that your services are in the same applicationcontext as your tx:annotation-driven...


    • #3
      thanks for getting back.

      I changed the flow so that the operation works fine when I invoke it within another flow using the persistence-context. here's my new flow:

      	<input name="applicationUser" />
      	<action-state id="setLastLoginDate">
      		<evaluate expression="userService.setLastLoginDate(applicationUser)" />
      		<transition to="saveUser"></transition>
      	<end-state id="saveUser" commit="true">
      That works and the update is completed. My userService is defined in a config file called bean-definitions-config.xml. my tx-annotationdriven is in data-access-config.xml. Are you saying they need to be in the same file? both files are loading using:

      <import resource="bean-definitions-config.xml" />
      	<import resource="data-access-config.xml" />
      In my web-application-config.xml file. will that not work?.......

      I think the way transactions are handled in web flow is different. I just can't figure out how it's done.