(MySQL)Spring3+Mybatis3使用注解式事务声明(@Transactional)无法回滚

按以下步骤进行检查:

1、检查下Spring3配置没问题(略);

2、检查Log4J日志输出,确实有进行事务回滚动作;

3、检查下MySQL后台日志输入,确实有进行“rollback”操作;

上网查找一番,终于找到解决方法!原来执行事务回滚的表默认“表类型=MyISAM“(网上说:MyISAM不支持事务!这个我不太清楚

使用如下语句更改表类型为”InnoDB“:

alter table equ_upkeep_plan ENGINE=INNODB其中,”equ_upkeep_plan“为表名!



展开阅读全文

spring3 注解事务不起作用

09-03

用spring3+hibernate配置注解式事务,测试的时候抛出异常总是不回滚。rn[size=medium][color=red]spring主配置文件hibernate.xml[/color][/size]rnrnrn rn rn rn rn rn rn rn rn rnrn rn rn rnrn rnrnrn rnrnrnrnrn rnrnrn rnrnrn rnrn rnrnrn rnrnrn rnrn rnrn rn rn rn rn classpath*:/com/qymgr/entity/hbm/*.hbm.xmlrn rn rn rn rn hibernate.dialect=org.hibernate.dialect.Oracle10gDialectrn hibernate.show_sql=truern hibernate.format_sql=truern hibernate.query.substitutions=true 1, false 0rn hibernate.jdbc.batch_size=20rn hibernate.c3p0.max_statements=0rn rn rn rn rnrn rn rn rnrn rn rn rn rn rn rn rn rnrn[size=medium][color=red]测试的DemoDao接口:DemoDao.java[/color][/size]rnpackage com.qymgr.sysmgr.dao;rnrnimport java.util.List;rnrnimport com.qymgr.entity.Demo;rnrnpublic interface DemoDaorn List findAll();rn void save(Demo demo);rnrn[size=medium][color=red]测试的实现类:DemoDaoImpl.java[/color][/size]rnpackage com.qymgr.sysmgr.dao.impl;rnrnimport java.util.List;rnrnimport javax.annotation.Resource;rnrnimport org.springframework.orm.hibernate3.HibernateTemplate;rnimport org.springframework.orm.hibernate3.support.HibernateDaoSupport;rnimport org.springframework.stereotype.Repository;rnimport org.springframework.transaction.annotation.Transactional;rnrnimport com.qymgr.entity.Demo;rnimport com.qymgr.sysmgr.dao.DemoDao;rn@Repositoryrn@Transactionalrnpublic class DemoDaoImpl extends HibernateDaoSupport implements DemoDaorn// @Resource HibernateTemplate hibernateTemplate;rn public List findAll()rn return getHibernateTemplate().find("from Demo");rn rn @Transactionalrn public void save(Demo demo)rn getHibernateTemplate().save(demo);rn throw new RuntimeException();rn rnrn抛出异常了,但是每回数据都成功插入了数据库,求大神指点 问答

求助,spring3 注解事务 回滚失败

07-03

[code=Java]rnrnrnrn rn rn rn jdbc:mysql://localhost:3306/hterp_2011?useUnicode=true&characterEncoding=UTF-8rn rn rn rn rn rn rnrn rn rnrn rnrn rn rn org.hibernate.dialect.MySQLDialectrn truern truern rn rn rn rnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnrn[/code]rn上面是我的spring配置文件rn[code=Java]rn@Transactional(propagation=Propagation.REQUIRED)rn public boolean saveDoodToStorage(GoodsArrivalForm form, Pager pager, Model model)rn rn// DefaultTransactionDefinition def = new DefaultTransactionDefinition(); rn// TransactionStatus status = transactionManager.getTransaction(def); rnrn /**rn * rn *这块为零星入库,需要跟原有的系统的采购入库集成,下面分为几步rn * rn *StorageListService 先创建入库单rn * rn *然后是入库单细目 StorageListDetailServicern * rn *接着是库存成本,就是记录库存中的每个商品的数量,价钱 GoodsCostServicern * rn *然后创建商品细目,记录一些入库单号,出库单号之类的 GoodsDetailServicern * rn *以上全部成功后,修改商品购买记录rn * rn */rn boolean succ = false;rn// try rn int goodsno = 0;rn // 入库的商品数量rn if(ObjectUtil.isNotEmpty(form.getGoodsno()))rn goodsno=form.getGoodsno();rn elsern if (ObjectUtil.isNotEmpty(form.getCode())) rn if (CollectionsUtil.notEmpty(form.getCode())) rn goodsno = form.getCode().length;rn rnrn rn rn rn rn if(goodsno<=0)rn return false;rn rn rn rn GoodsRecord gr = null;// 商品购买记录rn if (ObjectUtil.isNotEmpty(form.getGrid())) rn gr = grservice.find(form.getGrid());rn rn if (ObjectUtil.isEmpty(gr)) rn return false;rn rnrn Storage storage = null;rn if (ObjectUtil.isNotEmpty(form.getStoid())) rn storage = stoservice.find(form.getStoid());rn rn if (ObjectUtil.isEmpty(storage)) rn return false;rn rnrn StorageList storageList = new StorageList();rn Date createDate = new Date();rnrn storageList.setCode(codeService.createNewCode(CODE));rn storageList.setCreateDate(createDate);rn storageList.setCreateUser(form.getUser().getChinaname());rn storageList.setAuditStatus(1);// 零星入库为已审核状态rn storageList.setAboutTicket(form.getGrid() == null ? "" : formrn .getGrid().toString());// 相关单据号,这块为商品购买记录idrn storageList.setAboutTicketType(5);// 5为零星入库rnrn succ = slservice.saveOrUpdate(storageList);rn if (succ == false) rn return false;rn rn// throw new RuntimeException("aaaaaaa");rn List stolist = slservice.findByItem(storageList);rnrn if (ObjectUtil.isNotEmpty(stolist)) rn if (stolist.size() > 0) rn StorageList newsto = stolist.get(0);rnrn /**rn * 如果报销单保存成功,接下来为保存报销单细目rn */rn StorageListDetail stoderail = new StorageListDetail();rn stoderail.setStorageList(newsto);rn stoderail.setGoods(gr.getGoodsId());rn stoderail.setGoodsNo(Float.valueOf(goodsno));rn stoderail.setCost(gr.getPrice());rn stoderail.setCreateDate(createDate);rn stoderail.setStorageCode(storage.getCode());rn stoderail.setGoodsUnitId(1);rn succ = sldeservice.saveOrUpdate(stoderail);rnrn if (succ == false) rn return false;rn rnrn /**rn * 下面为保存具体的每个商品的入库条码信息 也就是商品细目rn */rnrn for (int i = 0; i < goodsno; i++) rnrn GoodsDetail gd = new GoodsDetail();rn gd.setCode("100010");rn gd.setGoodsId(gr.getGoodsId().getId());rn if(gr.getGoodsId().isEqualcode()==true)rn gd.setGoodsCode(form.getCode()[0]);rn elsern gd.setGoodsCode(form.getCode()[i]);rn rn rn rn gd.setStorage(storage);rn gd.setEnterDate(createDate);rn gd.setStatus(1);// 因为是零星入库,直接就是在库状态,跳过审核rn gd.setStorageInCode(newsto.getCode());rnrn succ = gdservice.saveOrUpdate(gd);rn if (succ == false) rn return false;rn rn rnrn /**rn *接下来为保存库存成本rn * rn *这块有待商榷,是否需要下次入库的时候,是修改原来的数据,还是新添加数据rn */rn GoodsCost goodscost = new GoodsCost();rn goodscost.setGoods(gr.getGoodsId());rn goodscost.setStorage(storage);rn goodscost.setStockNo(gr.getNum().floatValue());// 采购数量rn goodscost.setStorageNo(Float.valueOf(goodsno));// 库存数量rn goodscost.setNo(Float.valueOf(goodsno));rn goodscost.setTotalMoney(gr.getPrice() * goodsno);rn succ = goodscostservice.saveOrUpdate(goodscost);rn if (succ == false) rn return false;rn rnrn /**rn * 需要保存的数据全部成功后,修改商品购买记录的入库信息rn */rnrn Integer goodsnum = gr.getNum();rn Integer no = goodsno + gr.getInstoreNum();// 已入库数量加上这次入库的数量rnrn if (no < goodsnum) rn /**rn * 如果已入库数量加上这次入库的数量,小于总体的采购数量 则状态为部分入库rn */rn gr.setInstoreStatus(2);rnrn else rnrn gr.setInstoreStatus(3);rn rn gr.setInstoreNum(no);rnrn succ = grservice.saveOrUpdate(gr);rn if (succ == false) rn return false;rn rn rnrn rnrn rn throw new RuntimeException("aaaaaaa");rn// catch (Exception e) rn// // TODO: handle exceptionrn// throw e;rn// rnrn // return succ;rn rn[/code]rnrn抛出RuntimeException错误,没有集体回滚,求帮忙解决 论坛

没有更多推荐了,返回首页