Transaction question about HibernateTransactionManager
I have some troubles with transaction, my environnement is Hibernate / MySql and I use declarative transaction (PROPAGATION_REQUIRED) on my manager. Here a method on my manager, personne have a relation many-to-one with adresse, the cascade is all. if an exception is throwed during personne save, the adresse is not deleted.
Code:
public void save(Personne personne) throws ManagerException {
Adresse adresse = adresseDao.findByAdresse(personne.getAdresse());
if(adresse != null) {
personne.setAdresse(adresse);
}
personneDao.save(personne); >> Exception throwed here (duplicate key for my junit tests)
}
I use org.springframework.orm.hibernate.HibernateTransac tionManager as transaction manager.
By the way, I use also AOP to manage SQL exception so my manager declaration is like this :
Code:
<bean id="personneManagerTarget" class="com.euroflash.gestion.manager.impl.hbm.PersonneManagerImpl">
<property name="personneDao">
<ref bean="personneDao"/>
</property>
<property name="adresseDao">
<ref bean="adresseDao"/>
</property>
</bean>
<bean id="personneManagerHbm"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<ref bean="personneManagerTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="personneManager" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.euroflash.gestion.manager.PersonneManager</value>
</property>
<property name="target">
<ref local="personneManagerHbm"/>
</property>
<property name="interceptorNames">
<list>
<value>exceptionManager</value>
</list>
</property>
</bean>
Any ideas ?