Hello
I am using Spring 1.1. with Hibernate 2. The Spring transaction does not roll back when used in conjunction with Hibernate. I'm aware that this may be a Spring issue and is therefore not completely relevant but it may be Hibernate that is causing my problem.
The contents of my Spring configuration file are as follows:
<property name="transactionAttributes">
<props>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="create*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="process">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="authorise*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="terminate*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="cancel*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="find*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="test*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="warn*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
Code between sessionFactory.openSession() and session.close():
public final void testUpdateSwapRollback()
throws .......ValidationException, HibernateException {
LOG.debug("testUpdateSwapRollback starting...");
boolean testPassed = false;
Swap swap = null;
try {
// Create a swap and attempt to update it
SwapRequest swapRequest = toSwapRequest();
Long swapId = swapService.createSwap (swapRequest);
// Locate the swap
try {
swap = getSwapDao ().findSwapByPrimaryKey(new BigDecimal(swapId.longValue()));
} catch (ObjectRetrievalDAOException e) {
LOG.info(
"SwapServiceTest: testUpdateSwapRollback called findSwapByPrimaryKey and a swap was NOT returned",
e);
} catch (FinderDAOException e) {
LOG.error(
"testUpdateSwapRollback called findSwapByPrimaryKey and a swap was NOT returned",
e);
throw new XXXSystemException(
"testUpdateSwapRollback called findSwapByPrimaryKey and a swap was NOT returned", e);
}
// Modify the swap so that the effective date is 2 months BEFORE the trade date causing a ValidationException to be thrown
modifySwapInvalid(swap);
} catch (ValidationException e) {
LOG.info(
"testUpdateSwapRollback - Examine the database to see if the effective date for swap: "
+ swap.getSwapId()
+ " is before the trade date.",
e);
assertEquals(testPassed, true);
}
LOG.debug("testUpdateSwapRollback completed.");
}
Name and version of the database you are using:
Oracle 9i
Can anyone explain why the actions of the method modifySwapInvalid(swap) are not being rolled back?
|