EJB的事务怪问题 不能设置为required被调用的方法启动了一个新事务 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个问题没办法的,你只能写到一个session bean 中,多了session bean 调用不同的Entity Bean就是不回滚的!! to ljiangning(ljn):为什么会有这样的问题,难道EJB的规范它没遵守吗 不好意思,难道context.setRollbackOnly()是不需要调用的吗? chenyun(牛牛) :好象就是这个问题!能否给点例子? 不好意思,我也是刚学EJB。呵呵我是在Session Facade方法中捕获EntityBean的异常,然后回滚掉。Category是ValueObject,CategoryLocal是CMP Entity Bean public void setSessionContext(SessionContext ctx) { try { this.ctx = ctx; cmpHome = (CategoryLocalHome)JNDIRefFactory.newInstance().lookupLocalRef("java:comp/env/ejb/CategoryLocal"); } catch(Exception e) { logger.debug("[SessionFacadeBean.setSessionContext] " + e); } } public Category updateCategory(Category category) throws Exception { try { CategoryLocal categoryLocal = (CategoryLocal)cmpHome.findByPrimaryKey(category.getCategoryID()); categoryLocal.setName(category.getName()); categoryLocal.setDescription(category.getDescription()); categoryLocal.setKeyword(category.getKeyword()); return category; } catch(Exception e) { ctx.setRollbackOnly(); logger.debug("[SessionFacadeBean.updateCategory] " + e); throw e; } }不过1. 我没有试过你所说的Session Bean调用Session Bean,两个Session Bean又调用Entity Bean的。2. 我是在Session Facade中用RequiresNew,Entity Bean用Mandatory不知道对你有没有帮助 public Category updateCategory(Category category) throws Exception返回Category的原因是我加上了timestamp控制,不过为了给出的代码简单点,timestamp代码被我删掉了。一般返回void即可。不好意思,希望不至于产生误导。 OK,我这样测试过了:SessionBean1.foo(){ try { update CMP Entity Bean; call Sessionbean2.foo();// 抛出异常 } catch(Exception e) { ctx.setRollbackOnly(); }}两个Session Bean和Entity Bean都设为Required,结果顺利回滚了。虽然SessionBean2并没有调用Entity Bean,但是原理上应该是一样的。不过我不知道如果SessionBean2捕获自己的异常后就调用了setRollbackOnly,再抛出异常,那么是否就立刻回滚了,SessionBean1的setRollbackOnly将被忽略?不知那位能解答我的疑问? label和input输入域提交数据 JSP写留言本? comcat服务器集群和负载平衡 初学者 java 书籍 为什么XFire实现的WebService,在不同版本JRE会返回不同的数据包? 现求hibernate中多表查询语句? 求名词解释? 求教:axis开发问题!! 50分请问:哪里能下载《java xml 编程指南》 spring boot中redis事物问题 你为什么留下来? 如果客户端的字符给予负起的字符集不同怎么办??
为什么会有这样的问题,难道EJB的规范它没遵守吗
好象就是这个问题!能否给点例子?
{
try
{
this.ctx = ctx; cmpHome = (CategoryLocalHome)JNDIRefFactory.newInstance().lookupLocalRef("java:comp/env/ejb/CategoryLocal");
}
catch(Exception e)
{
logger.debug("[SessionFacadeBean.setSessionContext] " + e);
}
}
public Category updateCategory(Category category) throws Exception
{
try
{
CategoryLocal categoryLocal = (CategoryLocal)cmpHome.findByPrimaryKey(category.getCategoryID());
categoryLocal.setName(category.getName());
categoryLocal.setDescription(category.getDescription());
categoryLocal.setKeyword(category.getKeyword());
return category;
}
catch(Exception e)
{
ctx.setRollbackOnly();
logger.debug("[SessionFacadeBean.updateCategory] " + e);
throw e;
}
}
不过
1. 我没有试过你所说的Session Bean调用Session Bean,两个Session Bean又调用Entity Bean的。
2. 我是在Session Facade中用RequiresNew,Entity Bean用Mandatory不知道对你有没有帮助
{
try
{
update CMP Entity Bean;
call Sessionbean2.foo();// 抛出异常
}
catch(Exception e)
{
ctx.setRollbackOnly();
}
}两个Session Bean和Entity Bean都设为Required,结果顺利回滚了。虽然SessionBean2并没有调用Entity Bean,但是原理上应该是一样的。不过我不知道如果SessionBean2捕获自己的异常后就调用了setRollbackOnly,再抛出异常,那么是否就立刻回滚了,SessionBean1的setRollbackOnly将被忽略?不知那位能解答我的疑问?