I am new to spring and hibernate. I am running in a problem. I hope someone out there will help me!!!
Here is the situation. I am using spring 2.0.1 and Hibernate 3.2 on Jboss 4.0.5. I have a collection of
model objects and need to update each of them in separate transaction meaning failure of update operation on
one object should not affect the operation on other objects in the collection. For that, I created a parent method
that loops through the collection and calls a child method passing each of these objects which makes actual
database call through hibernate.
I am using following configuration.
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager">
<property name="transactionManagerName">
<value>java:/TransactionManager</value>
</property>
<property name="transactionSynchronization">
<bean id="org.springframework.transaction.jta.JtaTransac tionManager.SYNCHRONIZATION_NEVER"
class="org.springframework.beans.factory.config.Fi eldRetrievingFactoryBean"/>
</property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor .TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRES_NEW</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator">
<property name="beanNames">
<value>myService</value> <!-- myService bean has those methods to update the model object -->
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
For test purpose I am throwing RuntimeException from the child method like following.
public void updateModel(MyModel mm ,int i){
mmDao.update(mm); //hibernate dao
if(i%2 == 0) // doing this just to check - trying to make one call success and next one fail
throw new RuntimeException();
}
But everytime it is commiting the database change even if this child method is throwing exception. Could you please tell
me why?
P.S. I am catching exception in the web tier in order to show the user friendly message, so the exception does not bubble up to the opensessioninview filter.


Reply With Quote
