I have been trying to figure this out for two days without sucess. I am using annotation-driven transactions with Spring 3.0.5 and Postgress. I am calling two dao methods from a business logic method:
@Transactional
public void registerTransaction(GoogleTransaction transaction) {
long transactionID = DBFactory.getTransactionDBInstance().addTransaction(transaction);
DBFactory.getGoogleTransactionDBInstance().addGoogleTransaction(transaction, transactionID);
}
The second method (addGoogleTransaction) throws a RuntimeException at the end, however transaction is not rolled back and both rows are inserted.
The DAO method looks like this:
public void addGoogleTransaction(GoogleTransaction transaction, long id) {
log.trace("Entering addGoogleTransaction DAO method ");
log.trace(transaction.toString());
getSimpleJdbcTemplate().update(QRY_ADD_GOOGLE_TRANSACTION, new Object[] {id, transaction.getGoogleSerialNumber() ,
transaction.getGoogleBuyerID(), transaction.getGoogleOrderID()});
log.trace("Google transaction added successfully");
throw new RuntimeException();
}
The Spring configuration file:
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven />
Do I need to configure something else? I have tried to add @Transactional to the business logic class and @Transactional to the dao methods but it doesn't work neither. Thanx
It is called from a controller class (annotated with @Controller) for testing pursposes.
@RequestMapping(value = "/registration")
public String sendToRegistrationPage() throws ServiceException {
GoogleTransaction googleTransaction = new GoogleTransaction(0, "aei", new Date(), TransactionStatus.NEW, BigDecimal.ZERO, "", "", 0, "");
BillingFactory.getBillingImplementation("").registerTransaction(googleTransaction);
return "registration";
}