我们有一个 Spring Transaction 回滚问题,其中回滚似乎不起作用。
在我的服务层方法中,@Transactional我调用了三个不同的DAOImpl类来插入 3 条记录。
中间插入从第四个表中获取以填充描述字段,但这失败了。我希望第一个插入回滚,但它似乎没有发生。
几点:
- 'Get' 方法引发运行时异常
- 我们使用
org.springframework.jdbc.datasource.DataSourceTransactionManager并MySQL datasource定义在applicationContext.xml. Beans被创建在Beans.xml其中被导入ApplicationContext.xml - 图层中没有
@Transactional注释DAO - 我们
<tx:annotation-driven transaction-manager="transactionManager"/>在applicationContext.xml - 我们正在使用 Spring 3.1
更新:
代码片段....
服务类- 这与我所拥有的类似......我在有和没有@Autowired 的情况下进行了测试。在服务类中调用事务启用方法。
公共类客户服务{
//@自动连线
CustomerOrderDAO customerOrderDAOImpl;
//@自动连线
CustomerItemDAO customerItemDAOImpl;
//@自动连线
CustomerPromotionDAO customerPromotionDAOImpl;
//@自动连线
推广DAO 推广DAOImpl;
//其他变量
公共客户订单handleIncomingOrders(客户订单客户订单){
尝试 {
saveOrderDetails(customerOrder);
......
返回客户订单;
} catch (Exception e) //TO-DO 捕获正确的异常
{
//发送错误响应
…………
返回客户订单;
}
}
@Transactional
公共无效 saveOrderDetails(CustomerOrder customerOrder) 抛出异常 {
customerOrderDAOImpl.create(customerOrder);
……
while (promotionsIterator.hasNext()) {
customerPromotion.setPromotionName(promotionDAOImpl.getName(customerOrder.getPromotionId));
customerPromotionDAOImpl.create(customerPromotion);
}
……
while (customerItemIterator.hasNext()) {
customerItemDAOImpl.create(customerItem);
}
}
}
任何的想法?谢谢。