Hi guys
I have a problem with transactionManager. The rollback does not work. I'm using Spring 3.0.6 and Hibernate 3.9.0
My settings
Code:
<context:annotation-config/>
<context:component-scan base-package="project.cmi"/>
<tx:annotation-driven transaction-manager="txManager"/>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:project/cmi/jdbc.properties"/>
</bean>
<bean id="cmiDS"
class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="cmiDS"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="cmiDS"/>
<property name="packagesToScan" value="project.cmi.domain"/>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.show_sql=true
hibernate.format_sql=true
</value>
</property>
</bean>
Code:
@Repository("contactRepository")
public class ContactRepository {
@Autowired
private SessionFactory sessionFactory;
public void persist(Contact contact){
sessionFactory.getCurrentSession().save(contact);
}
}
Code:
@Transactional(readOnly=true)
@Service("contactService")
public class ContactService {
@Autowired
private ContactRepository contactRepository;
@Transactional(propagation=Propagation.REQUIRED, readOnly=false, rollbackFor={RuntimeException.class})
public void persist(Contact contact) throws Exception {
contatoRepository.persist(contact);
throw new RuntimeException; //The rollback does not work
}
}
Thank you for help!