We have a Spring Transaction rollback issues, where rollback doesn't seems to be working.
Within my service layer method which is annotated with @Transactional I call three different DAOImpl classes to insert 3 records.
The middle insert do a get from a 4th table to populate a description field but this get failed. I expect the first insert to rollback but it doesn't seems to be happening.
Few Points:
- The 'Get' method throws a Runtime Exception
- We are using
org.springframework.jdbc.datasource.DataSourceTransactionManagerandMySQL datasourcedefined inapplicationContext.xml. Beans are created inBeans.xmlwhich is imported intoApplicationContext.xml - No
@Transactionalannotation inDAOlayer - We have used
<tx:annotation-driven transaction-manager="transactionManager"/>again inapplicationContext.xml - We are using Spring 3.1
UPDATE:
Code snippets....
Service Class- This is somthing similar to what I have .... I tested with and without @Autowired. The transaction enable method is called within the service class.
public class CustomerService {
//@Autowired
CustomerOrderDAO customerOrderDAOImpl;
//@Autowired
CustomerItemDAO customerItemDAOImpl;
//@Autowired
CustomerPromotionDAO customerPromotionDAOImpl;
//@Autowired
PromotionDAO promotionDAOImpl;
//other variables
public CustomerOrder handleIncomingOrders(CustomerOrder customerOrder) {
try {
saveOrderDetails(customerOrder);
.....
return customerOrder;
} catch (Exception e) //TO-DO catch proper exception
{
//Send error response
.......
return customerOrder;
}
}
@Transactional
public void saveOrderDetails(CustomerOrder customerOrder) throws Exception {
customerOrderDAOImpl.create(customerOrder);
....
while (promotionsIterator.hasNext()) {
customerPromotion.setPromotionName(promotionDAOImpl.getName(customerOrder.getPromotionId));
customerPromotionDAOImpl.create(customerPromotion);
}
......
while (customerItemIterator.hasNext()) {
customerItemDAOImpl.create(customerItem);
}
}
}
Any idea? Thanks.