spring 异常 事物不回滚

mysql中spring.xml里配置了AOP通知,事物管理等,但是代码异常数据却没有回滚,因为事物是走的mysql默认的事物,没有走自己配置的

引入

<aop:aspectj-autoproxy />

spring事务遇到异常回滚

03-11

测试代码: rnApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml"); rnStudentDAOI studao = (StudentDAOI)app.getBean("studentDaoProxy"); rnstudao.save(student); rnrnsave方法: rnpublic void save(Student student) rngetHibernateTemplate().save(student); rnthrow new RuntimeException("aaaaaa"); rn rnrn配置如下: rnrn rn rn rn rn rncom.jwgl.vo.StudentDAOI rn rn rn rn rn rn rn rn rn rnPROPAGATION_REQUIRED rn rn rn rnrn不抛异常的时候能够正常插入数据: 抛出运行时异常是报错如下: rnrnException in thread "main" java.lang.RuntimeException: aaaaaa rnat com.jwgl.vo.StudentDAO.save(StudentDAO.java:33) rnat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) rnat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) rnat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) rnat java.lang.reflect.Method.invoke(Method.java:597) rnat org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304) rnat org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) rnat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) rnat org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) rnat org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) rnat org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) rnat $Proxy1.save(Unknown Source) rnat com.jwgl.test.StudentDaoTest.main(StudentDaoTest.java:24)

spring事务不回滚

03-01

初学spring,然而调试了好久,都没能让其声明式事务发挥作用,无奈,求助!rnrnspring配置文件:rnrn[code=XML]rnrnrnrnrn rn com.mysql.jdbc.Driverrn jdbc:mysql://localhost:3306/ormrn rootrn rootrn rn rn rn rn rn rn com/itlover/hibernate/User.hbm.xmlrn com/itlover/hibernate/Card.hbm.xmlrn rn rn rn rn org.hibernate.dialect.MySQLDialectrn truern rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn PROPAGATION_REQUIRED,-Exceptionrn rn rn rn rn rn rn rn rnrn[/code]rnrn执行操作的是保存一个 User, User跟Card进行cascade级联,即保存User时也让Hibernate保存Cardrnrn,程序中故意把 card.setCardBankname("招商银行"); 给注释掉(此属性不能为空),就是希望在此处可以看到rnspring的事务是否生效...rnrnrn具体代码为:rnrn[code=Java]rnAction.javarnrnpublic ActionForward test(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exceptionrn rn User user = new User();rn user.setUserName("susan");rn user.setUserAge(21);rn rn Card card = new Card();rn // card.setCardBankname("招商银行");rn card.setCardNumber("6225888811558899");rn card.setUser(user);rn rn user.getCards().add(card);rn rn baseService.saveEntity(user);rn rn return null;rn rnrnrnService.javarnrnpublic class DefaultServiceImpl implements BaseServicernrn private BaseDao baseDao;rn public void saveEntity(Object entity)rn rn baseDao.saveEntity(entity);rn rn rn public void setBaseDao(BaseDao baseDao)rn rn this.baseDao = baseDao;rn rnrnrnrnDao.javarnrnpublic class DefaultDaoImpl extends HibernateDaoSupport implements BaseDaornrn public void saveEntity(Object entity)rn rn getHibernateTemplate().save(entity);rn rnrnrn[/code]rnrnrn执行的结果:是user对象被持久化了...rnrnrn正确的结果应该是因为card不能被持久化,而整个事务回滚,即user不应被持久化才是rnrnrnrn大家帮帮忙啊

spring 事务 不回滚

09-06

执行中抛出 sql异常 而没有抛出 spring的 dataaccess 异常rnrn rnrn rn rn rn rn rnrn rnrn rn rn rn rn rnrn rnrn rnrn rn rn rn rn rn rn rn rn rn PROPAGATION_REQUIREDrn rn rn rn truern rn rn rn rn rn rn rn rnrn rnrn测试类 rnrn rnrn rnrnpackage com.zyb.jsh.bl;rnrnimport com.zyb.jsh.db.BaseSHDao;rnimport com.zyb.jsh.db.UserInfo;rnrnpublic class BLTestDaoAction rnrn private BaseSHDao commonDao;rn private UserInfo user;rnrn public String testDao() rn rn String loginResult = "failure";rn rn BaseSHDao commonDaoIns = this.getCommonDao();rn rn commonDaoIns.insert(this.user);rnrn//插入同样的数据违反,唯一性约束,抛出异常rn commonDaoIns.insert(this.user);rnrn return loginResult;rn rnrn public BaseSHDao getCommonDao() rn return commonDao;rn rnrn public void setCommonDao(BaseSHDao commonDao) rn this.commonDao = commonDao;rn rn rnrn public UserInfo getUser() rn return user;rn rnrn public void setUser(UserInfo user) rn this.user = user;rn rnrnrnrn抛出的异常rnrn rnrncom.ibm.db2.jcc.a.SqlException: DB2 SQL error: SQLCODE: -803, SQLSTATE: 23505, SQLERRMC: 2;ADMINISTRATOR.USERrncom.ibm.db2.jcc.a.tf.d(tf.java:1397)rncom.ibm.db2.jcc.b.jb.l(jb.java:367)rncom.ibm.db2.jcc.b.jb.a(jb.java:64)rncom.ibm.db2.jcc.b.w.a(w.java:48)rncom.ibm.db2.jcc.b.dc.b(dc.java:302)rncom.ibm.db2.jcc.a.uf.cb(uf.java:1739)rncom.ibm.db2.jcc.a.uf.d(uf.java:2339)rncom.ibm.db2.jcc.a.uf.Y(uf.java:544)rncom.ibm.db2.jcc.a.uf.executeUpdate(uf.java:527rnrn。。。。。rnrn

spring的事务不回滚

01-12

rn rn rnrn rn rn rn rn rn rnrnrn rn rnrnrnrn不知道为什么已经配置成这样了,还是不回滚rnrnrnrn我在中间层加了一个rnpuf.insertProductUpgradeAndUpdateSoftSN(ssn, i);rn String s = null;rn String a = s.toLowerCase();rnrn肯定会抛出一个空指针异常。不知道为什么,不回滚。rnrn[code=Java]rnpackage com.autonavi.sgm.domain.logic.batchupgrade;rnrnimport java.io.FileNotFoundException;rnimport java.io.IOException;rnimport java.util.Date;rnimport java.util.List;rnrnimport org.springframework.beans.factory.annotation.Autowired;rnimport org.springframework.beans.factory.annotation.Qualifier;rnimport org.springframework.stereotype.Component;rnimport org.springframework.stereotype.Repository;rnimport org.springframework.transaction.annotation.Propagation;rnimport org.springframework.transaction.annotation.Transactional;rnrnimport com.autonavi.sgm.dao.bean.Dealer;rnimport com.autonavi.sgm.dao.bean.FileManage;rnimport com.autonavi.sgm.dao.bean.ProductUpgrade;rnimport com.autonavi.sgm.dao.bean.SoftSN;rnimport com.autonavi.sgm.domain.logic.Softsn.SoftSNFacade;rnimport com.autonavi.sgm.domain.logic.dealer.DealerFacade;rnimport com.autonavi.sgm.domain.logic.filemanage.FileManageFacade;rnimport com.autonavi.sgm.domain.logic.product.ProductFacade;rnimport com.autonavi.sgm.domain.logic.productupgrade.ProductUpgradeFacade;rnimport com.autonavi.sgm.util.SGMJavaConPOI;rnimport com.op.WLD4Update;rnrn@Component(value = "batchUpgradeFacade")rn@Transactional(readOnly = false)rn@Repositoryrnpublic class BatchUpgradeImpl implements BatchUpgradeFacade rnrn private SGMJavaConPOI sgmc = new SGMJavaConPOI();rnrn @Autowiredrn @Qualifier("productFacade")rn private ProductFacade pf;rnrn @Autowiredrn @Qualifier("dealerFacade")rn private DealerFacade df;rnrn @Autowiredrn @Qualifier("softSNImpl")rn private SoftSNFacade ssf;rnrn @Autowiredrn @Qualifier("productUpgradeFacade")rn private ProductUpgradeFacade puf;rnrn @Autowiredrn @Qualifier("fileManageFacade")rn private FileManageFacade ff;rnrn /*@Transactional(readOnly = false, propagation = Propagation.NESTED, rollbackFor = rn Exception.class, RuntimeException.class )*/rn public String setExcelUpgrade(List listupgrade,rn List snList, String filePath, String filename)rn throws Exception rn // TODO Auto-generated method stubrn String info = null;rn if (listupgrade != null) rn for (ProductUpgrade i : listupgrade) rn SoftSN ssn = snList.get(0);rn ssn.setStatus("100501");rn String sn = ssn.getSn();rn String tmpsn = sn.replaceAll("-", "");rn i.setSn(sn);rn String vin = i.getVin();rn String mapedition = i.getMedition();rn vin = "51AF484D00005C35328DD610766C56F9";// 测试数据rn String strDevCode = WLD4Update.GetDevCode(tmpsn, vin, 5, 3, 40,rn 24);rn i.setRn(strDevCode);rn String dcode = i.getField1();rn Dealer dl = df.findByDcode(dcode);rn i.setSid(dl.getId());rn i.setMedition(mapedition);rn i.setCtime(new Date());rn i.setStatus("100100");rn puf.insertProductUpgradeAndUpdateSoftSN(ssn, i);rn String s = null;rn String a = s.toLowerCase();rn /*rn * ssf.updateSoftSn(ssn); puf.insertProductUpgrade(i);rn */rnrn snList.remove(ssn);rnrn rnrn String resultInfo = sgmc.setExcelUpgrade(filePath, "清单", filename,rn listupgrade);// resultInfo是结果信息,成功与否rnrn FileManage fm = new FileManage();rn fm.setCtime(new Date());rn fm.setFilename(filename);rn fm.setAddress(filePath);rn ff.insertFileManage(fm);rn System.out.println(filePath);rn return resultInfo;rn else rn info = "list为空!";rn return info;rn rn rnrnrnrn[/code]rn

spring 事务不回滚

03-20

[color=#FF0000]我的applicationContext.xml配置如下:[/color]rnrnrnrn rn rn com.mysql.jdbc.Driverrn rn rn jdbc:mysql://localhost:3306/bbsrn rn rn rn rnrn rn rn rn rnrn rn rn rn org.hibernate.dialect.MySQLDialectrn rn truern rn rn rn rn classpath:pojorn rn rn rnrn rn rn rn rn rnrnrn rnrn rn rn rn rnrn rnrn rn rn rn rnrn rn rn PROPAGATION_REQUIREDrn rn PROPAGATION_REQUIREDrnrn PROPAGATION_REQUIREDrnrn PROPAGATION_REQUIREDrnrn PROPAGATION_REQUIREDrnrn PROPAGATION_REQUIRED,readOnlyrnrn PROPAGATION_REQUIRED,readOnlyrnrn PROPAGATION_REQUIRED,readOnlyrnrn PROPAGATION_REQUIRED,readOnlyrnrn PROPAGATION_REQUIRED,readOnlyrnrn PROPAGATION_REQUIRED,readOnlyrnrn PROPAGATION_REQUIRED,readOnlyrnrn rnrn rn rnrn rn rn rn rn rn rn loginDaorn rn rn rnrn rn rn rn transactionInterceptorrn rn rn rnrn[color=#FF0000]Dao接口是:[/color]rnpublic interface IDao rn public abstract void save(Object entity);rn public abstract void delete(Object entity); rn public abstract void update(Object entity);rn public List find(String queryString,Object[] value);rnrn[color=#FF0000]Dao是:[/color]rnpublic class LoginDao extends HibernateDaoSupport implements IDao rnrn public void save(Object entity) rn getHibernateTemplate().save(entity);rn rnrn public void delete(Object entity) rn getHibernateTemplate().delete(entity); rn rnrn @SuppressWarnings("unchecked")rn public List find(String queryString,Object[] value) rn return (List)getHibernateTemplate().find(queryString, value);rn rnrn public void update(Object entity) rn getHibernateTemplate().update(entity); rn rnrn[color=#FF0000]在这个action中我想测试事务回滚;[/color]rnpublic class Forumdelete extends ActionSupportrn public IDao loginDao;rn public int id;rn rn public IDao getLoginDao() rn return loginDao;rn rn public void setLoginDao(IDao loginDao) rn this.loginDao = loginDao;rn rn rn public int getId() rn return id;rn rn public void setId(int id) rn this.id = id;rn rn public String execute() throws Exceptionrn String hql1 = "from Forum fm where fm.Id=?";rn Object[] value1= new Object[] this.id;rn List i = (List) loginDao.find(hql1, value1);rn loginDao.delete(i.get(0));rn String hql2="from Topic tp where tp.Id=?";rn Object[] value2=new Object[]i.get(0).getUsernametopic().iterator().next().getId();rn List ii=(List) loginDao.find(hql2, value2);//[color=#FF0000]此处抛出异常[/color]rn loginDao.delete(ii);rn String hql3="from Reponse rp where tp.Topicid=?";rn Object[] value3=new Object[]ii.get(0).getId();rn List iii=(List) loginDao.find(hql3, value3);rn loginDao.delete(iii);rn return SUCCESS;rn rnrnrnrn为什么不回滚?rn

winform的事物回滚问题

12-09

代码如下:[code=C#]rn PLT.BLL.SYS_PUBLIC bpub = new PLT.BLL.SYS_PUBLIC();rn SqlConnection Conn = bpub.SqlConn();rn SqlTransaction trans = Conn.BeginTransaction();rntryrn rn rn gFunc.SaveGridTrans(ref Conn, ref trans, ref id_Grid2, "BI_CONTACT Where C_TYPE = '1'");rn gFunc.SaveGridTrans(ref Conn, ref trans, ref id_Grid3, "BI_CONTACT Where C_TYPE = '2'");rn gFunc.SaveGridTrans(ref Conn, ref trans, ref id_Grid4, "BI_CARGO");rn gFunc.SaveGridTrans(ref Conn, ref trans, ref id_Grid5, "BI_QUOTE");rnrn trans.Commit();rnrn MessageBox.Show("保存成功!");rn rn catch (Exception ex)rn rn trans.Rollback();rn rn finallyrn rn if (Conn.State == ConnectionState.Open)rn rn Conn.Close();rn Conn.Dispose();rn rn rn rn[/code]rnrn公用函数如下:rn[code=C#]rn public static void SaveGridTrans(ref SqlConnection SendConn, ref SqlTransaction SendTran, ref DataSet SendDs, string Sendtbname)rn rn SqlCommand sqlcmd = new SqlCommand();rn SqlDataAdapter sqlada = new SqlDataAdapter();rn sqlcmd.Connection = SendConn;rn sqlcmd.Transaction = SendTran;rn sqlcmd.CommandText = "Select * From " + Sendtbname;rn sqlada.SelectCommand = sqlcmd;rn SqlCommandBuilder Sqlcb = new SqlCommandBuilder(sqlada);rn sqlada.Update(SendDs.Tables[0]);rn SendDs.Tables[0].AcceptChanges();rn rn[/code]rnrn当保存id_Grid3时,如果出错回滚,再次保存id_Grid2时就会报:rn违反并发性: UpdateCommand 影响了预期 1 条记录中的 0 条。rnrn应该是id_grid2被更新过但是没有回滚,为什么会这样?如何处理

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

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试