在ejb中调用con的commit或者rollback为何发生错误!

pqds 2003-12-12 11:12:15
java.sql.SQLException: Cannot call Connection.commit in distributed transaction. Transaction Manager will commit the resource manager when the distributed transaction is committed


怎么解决!

...全文
421 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
pqds 2003-12-12
  • 打赏
  • 举报
回复
主要还是这个错误!
java.lang.IllegalStateException: Transaction does not exist
pqds 2003-12-12
  • 打赏
  • 举报
回复
不行呀!
The commit error is java.lang.NullPointerException
现在式这个!
coolyzg 2003-12-12
  • 打赏
  • 举报
回复
UserTransaction ut = null;
try
{
ut = sessionContext.getUserTransaction();
ut.begin();
Call_updateSQL(bufSql.toString());

String sq1 = "inset into MS_USER_VERIFY(ID) values ('www')";
Call_updateSQL(sq1);

ut.commit();
}catch(Exception ex)
{
try
{
ut.rollback();
}catch(Exception e)
{
System.out.println("The rollback error is"+e);
}
System.out.println("The commit error is"+ex);
return;
}

}

这样应该可以了
pqds 2003-12-12
  • 打赏
  • 举报
回复
现在改成bean管理的!s式无状态的!

try
{
UserTransaction ut = sessionContext.getUserTransaction();

Call_updateSQL(bufSql.toString());

String sq1 = "inset into MS_USER_VERIFY(ID) values ('www')";
Call_updateSQL(sq1);
ut.begin();
ut.commit();
}catch(Exception ex)
{
try
{
UserTransaction ut = this.sessionContext.getUserTransaction();
ut.rollback();
}catch(Exception e)
{
System.out.println("The rollback error is"+e);
}
System.out.println("The commit error is"+ex);
return;
}

}
现在错误如下:
The rollback error isjava.lang.IllegalStateException: Transaction does not exist

AllError 2003-12-12
  • 打赏
  • 举报
回复
如果你的ejb事务是容器管理的。Connection.commit或rollback是不能用的
gunandrose 2003-12-12
  • 打赏
  • 举报
回复
Connection.commit

这个方法不要用
ladofwind 2003-12-12
  • 打赏
  • 举报
回复
记得ejb有个设置tansaction的地方,如果required的话,
ejb containner自己处理事务的提交回滚,你查查你的设置
gunandrose 2003-12-12
  • 打赏
  • 举报
回复
把你的代码贴出来,看看
blueye11 2003-12-12
  • 打赏
  • 举报
回复
从那个错误来看,还是会话bean的状态的问题啊,为什么说是非法的state 呢
george2000 2003-12-12
  • 打赏
  • 举报
回复
我想只要你配置成基于bean管理的就应该可以使用connection的commit/rollback了。

你好好试一下,不知道为什么使用UserTransaction这种方式不行。
george2000 2003-12-12
  • 打赏
  • 举报
回复
奇怪了,我使用UserTransaction这种方式进行commit/rollback操作是不成功的。而直接使用connection的commit/rollback确是好用的。

我创建的ejb是无状态的session bean(基于bean管理的)。

我想你还是看看你原先的程序哪个地方写的不对吧。



wuyg719 2003-12-12
  • 打赏
  • 举报
回复
try{
System.out.println(bufSql.toString());
UserTransaction ut = sessionContext.getUserTransaction();
ut.begin();
Call_updateSQL(bufSql.toString());
ut.commit();
}catch(Exception ex)
{
try
{
ex.printStack();
if (ut!=null) ut.rollback();
throw ex;
}catch(Exception e)
{
System.out.println("The rollback error is"+e);
}
System.out.println("The commit error is "+ex);
}
coolyzg 2003-12-12
  • 打赏
  • 举报
回复
我觉的你可能没设置成bean管理
pqds 2003-12-12
  • 打赏
  • 举报
回复
错误
The rollback error isjava.lang.NullPointerException
The commit error is java.lang.NullPointerException
pqds 2003-12-12
  • 打赏
  • 举报
回复
try{
System.out.println(bufSql.toString());
UserTransaction ut = sessionContext.getUserTransaction();
ut.begin();
Call_updateSQL(bufSql.toString());
ut.commit();
}catch(Exception ex)
{
try
{
UserTransaction ut = sessionContext.getUserTransaction();
ut.rollback();
throw ex;
}catch(Exception e)
{
System.out.println("The rollback error is"+e);
}
System.out.println("The commit error is "+ex);
}

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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