Announcement Announcement Module
Collapse
No announcement yet.
Transaction issues (migration from spring 1.2.8 to 3.0.1) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction issues (migration from spring 1.2.8 to 3.0.1)

    Hi,

    I’m having transaction issues migrating from spring 1.2.8 to 3.0.1 (with hibernate from 3.1.3 to 3.3.1)

    Here’s the problem:

    I have a java service (myService.java) with those parameters:
    Code:
    <property name="transactionAttributes">
    			<props>
    				<prop key="process">PROPAGATION_REQUIRED, readOnly</prop>
    				<prop key="save">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>
    			</props>
    </property>
    This service has 2 methods:

    The “process” method does stuffs without any writing in the database (readOnly)
    The “save” method will save the result of “process” method into the database.

    Here’s the code of process method:
    Code:
    public void process(){
    	// some work
    	…
    	
    	MyService service = 
                (MyService) new ClassPathXmlApplicationContext(
                            "classpath:/context.xml"). getBean(
                    «myService»);
    
          // calling « save » method to save into database:        
           service.save(processResult);
    }
    This code was working fine with spring 1.2.8. When the “process” method is called, we also have the “save” method called and data saved in the database. Even if “process” is defined as “readOnly” method, because the service is reinstantiated (getBean…) so another transaction created and calling “save” won’t fail because “save” is not set to “readOnly”.

    With spring 3.0.1, there’s nothing saved in the database by the “save” method. The only way to have something saved is to remove the “readOnly” keyword on the “process” transaction configuration or moving the “save” method call out of “process” method.

    Is there a way to have the previous behaviour with spring 3.0.1? Because I have a lot of services following this schema, so moving out the “save” method from “process” will take a lot of time and removing “readOnly” creates performances issues.
    Last edited by jaypi; Oct 26th, 2010, 02:24 AM.

  • #2
    I'm using Websphere Application Server 6.1.0.9.

    Here's the configuration:

    dao.xml: (DAO layer)
    Code:
    <bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager">
    			<ref local="transactionManager"/>
    		</property>
    		<property name="transactionAttributes">
    			<props>
    			
    				<prop key="calcul*">PROPAGATION_SUPPORTS, readOnly</prop>
    				<prop key="exist*">PROPAGATION_SUPPORTS, readOnly</prop>
    				<prop key="hasLinked*">PROPAGATION_SUPPORTS, readOnly</prop>
    				<prop key="is*">PROPAGATION_SUPPORTS, readOnly</prop>
    				<prop key="load*">PROPAGATION_SUPPORTS, readOnly</prop>
    				<prop key="get*">PROPAGATION_SUPPORTS, readOnly</prop>
    				<prop key="search*">PROPAGATION_SUPPORTS, readOnly</prop>  
    				<prop key="lister*">PROPAGATION_SUPPORTS, readOnly</prop>
    				
    				<prop key="coche*">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>
    				<prop key="delete*">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>
    				<prop key="update*">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>
    				<prop key="save*">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>
    				<prop key="set*">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>
    				<prop key="ajout*">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>               
    				<prop key="creer*">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>    
    				<prop key="sauvegarde*">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>            
    				<prop key="supprime*">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>                    
    			
    			</props>
    		</property>
    	</bean>
    
    <bean id="myDao" parent="txProxyTemplate" scope="singleton">
    		<property name="target">
    			<bean class="com.package.myDaoIml">
    				<property name="sessionFactory">
    					<ref local="sessionFactory"/>
    				</property>
    			</bean>
    		</property>
    	</bean>
    bo.xml: (domain layer)
    Code:
    <bean id="myBo" class="com.package.myBoImpl">
    		<property name="myDao">
    			<ref local="myDao" />
    		</property>
    	</bean>
    service.xml (service layer)
    Code:
    <bean id="myService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" scope="singleton">
    		<property name="transactionManager">
    			<ref local="transactionManager"/>
    		</property>
    		<property name="target">
    			<ref local="myServiceTarget"/>
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="faireSimulationRev">PROPAGATION_REQUIRED, readOnly</prop>
    				<prop key="sauvegarderSimulationRev">PROPAGATION_REQUIRED, ISOLATION_READ_COMMITTED,-CefiException</prop>
    			</props>
    		</property>
    	</bean>
    	
    	<bean id="myServiceTarget" class="com.package.myServiceImpl">
    		<property name="myBo">
    			<ref local="myBo"/>
    		</property>
    	</bean>
    common configuration:
    Code:
    <!-- Hibernate SessionFactory -->
    
    	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource">
    			<ref local="dataSource" />
    		</property>
    		<property name="mappingResources">
    			<list>
    				<value>com/package/myObject.hbm.xml</value>
    				...		    
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">tmp.pag.SQLServerDialect</prop>
    				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    				<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
    				<prop key="hibernate.cache.use_second_level_cache">true</prop>
    				<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
    				<prop key="hibernate.cache.use_query_cache">true</prop>
    				<prop key="hibernate.cache.query_cache_factory">org.hibernate.cache.StandardQueryCacheFactory</prop>
    				<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
    				<prop key="hibernate.cache.use_structured_entries">true</prop>
    			</props>
    		</property>
    	</bean>
    
    	<!-- End of Hibernate SessionFactory -->
    
    	<!--Transaction Management-->
    
    	<bean id="transactionManager" scope="singleton" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref local="sessionFactory" />
    		</property>
    		<property name="hibernateManagedSession" value="false" />
    	</bean>
    
    	<!--End of Transaction Management-->
    
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    	<property name="jndiName">
    		<value>jdbc/CEFI_P_MS_MS</value>
    	</property>
    </bean>

    Comment

    Working...
    X