`

spring管理hibernate事务报异常--Transaction not successfully started解决方法

 
阅读更多
通过spring管理配置了事务管理,但是在执行过程中还是出现了异常:
Transaction not successfully started

以下三段代码均报了该异常。

  1. 1.
  2. publicvoidupdateProcInstObj(TaProcInsttaProcInstObj_from2)throwsException{
  3. Stringhql="updateTaProcInstsetinststate=?,runtimes=?,completetime=?whereprocinstid=?";
  4. this.getSession.createQuery(hql)
  5. .setString(0,taProcInstObj_from2.getInststate())
  6. .setInteger(1,taProcInstObj_from2.getRuntimes().intValue())
  7. .setString(2,taProcInstObj_from2.getCompletetime())
  8. .setString(3,taProcInstObj_from2.getProcinstid())
  9. .executeUpdate();
  10. }
  11. 2.
  12. publicvoidupdateProcInstObj(TaProcInsttaProcInstObj_from2)throwsException{
  13. TransActiontransAction=this.getSession().getTransAction();
  14. transAction.begin();
  15. Stringhql="updateTaProcInstsetinststate=?,runtimes=?,completetime=?whereprocinstid=?";
  16. this.getSession.createQuery(hql)
  17. .setString(0,taProcInstObj_from2.getInststate())
  18. .setInteger(1,taProcInstObj_from2.getRuntimes().intValue())
  19. .setString(2,taProcInstObj_from2.getCompletetime())
  20. .setString(3,taProcInstObj_from2.getProcinstid())
  21. .executeUpdate();
  22. transAction.commit();
  23. }
  24. 3.
  25. publicvoidupdateProcInstObj(TaProcInsttaProcInstObj_from2)throwsException{
  26. TransActiontransAction=this.getSession().beginTransAction();
  27. Stringhql="updateTaProcInstsetinststate=?,runtimes=?,completetime=?whereprocinstid=?";
  28. this.getSession.createQuery(hql)
  29. .setString(0,taProcInstObj_from2.getInststate())
  30. .setInteger(1,taProcInstObj_from2.getRuntimes().intValue())
  31. .setString(2,taProcInstObj_from2.getCompletetime())
  32. .setString(3,taProcInstObj_from2.getProcinstid())
  33. .executeUpdate();
  34. transAction.commit();
  35. }

修改为如下的方式则可以解决此问题:
  1. publicvoidupdateProcInstObj(TaProcInsttaProcInstObj_from2)throwsException{
  2. Sessionsession=this.getSession();
  3. Stringhql="updateTaProcInstsetinststate=?,runtimes=?,completetime=?whereprocinstid=?";
  4. session.createQuery(hql)
  5. .setString(0,taProcInstObj_from2.getInststate())
  6. .setInteger(1,taProcInstObj_from2.getRuntimes().intValue())
  7. .setString(2,taProcInstObj_from2.getCompletetime())
  8. .setString(3,taProcInstObj_from2.getProcinstid())
  9. .executeUpdate();
  10. session.flush();
  11. session.clear();
  12. }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics