关于Spring事务不起作用,哪位能帮忙看看啊,谢谢。

myepoch 2014-01-27 02:42:00
真实的代码如下,事务不起作用。往下继续看,起作用。

针对doPost和doExecute做了事务配置
<tx:method name="doExecute" propagation="REQUIRED" />
--------------------------------
public class EntryServlet extends HttpServlet{

public void init(ServletConfig config) throws ServletException {

}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{


IService service = null;

String newJson=strJson(content,0);
service = (IService)BeanService.getBean("shtg");
str=service.doExecute(newJson);//对应Shtg类


newJson=strJson(content,1);
service = (IService)BeanService.getBean("jyztUpdate");
str=service.doExecute(newJson); //对应JyztUpdate 类

}

public void destroy(){

}
}

public class Shtg{
public String doExecute(String jsonStr) throws RuntimeException {

String sql= "update GadwRyXx set jyzt = :jyzt,kyzt='Addd' where guid = :guid and kyzt = '1'";
baseDao.update(sql, parameters);

}
}

public class JyztUpdate{
public String doExecute(String jsonStr) throws RuntimeException {

baseDao.saveObj(gsh);

}
}


-------------------------------------------------------------------------------------
如果将代码变更下,事务就起作用。
public class EntryServlet extends HttpServlet{

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{


IService service = null;

String newJson=strJson(content,0);
service = (IService)BeanService.getBean("shtg");
str=service.doExecute(newJson);//对应Shtg类


//newJson=strJson(content,1);
//service = (IService)BeanService.getBean("jyztUpdate");
//str=service.doExecute(newJson); //对应JyztUpdate 类

}


}

public class Shtg{
public String doExecute(String jsonStr) throws RuntimeException {

baseDao.saveObj(gsh);//注意,此处将保存写在Shtg类的doExecute方法,事务就起作用


String sql= "update GadwRyXx set jyzt = :jyzt,kyzt='Addd' where guid = :guid and kyzt = '1'";
baseDao.update(sql, parameters);

}
}

...全文
134 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
myepoch 2014-01-27
  • 打赏
  • 举报
回复
这个问题之前有人帮忙,但是还没有解决。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧