首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

UserTransaction.begin抛System.NotSupportedException

2014-01-26 
Java codepublic static UserTransaction beginTransaction()throws PLMSystemException {if (log.isDebugE

Java code
public static UserTransaction beginTransaction()throws PLMSystemException {if (log.isDebugEnabled())log.debug('');UserTransaction tx = null;try {Context initialContext = new InitialContext();tx =(UserTransaction) initialContext.lookup('java:comp/UserTransaction');//set timeout for 1 hourtx.setTransactionTimeout(3600);tx.begin();} catch (Exception e) {throw new PLMSystemException(e, new LogExceptionHandler());}return tx;}



代码如上,第一次调就抛异常,会是什么原因?

------解决方法--------------------------------------------------------
System.NotSupportedException -

Thrown if the thread is already associated with a transaction and the Transaction Manager implementation does not support nested transactions


现成已经与一个 事务相关了,而且又不允许嵌套事务

所以报错了

tx.begin(); 这行注释掉应该就好了

------解决方法--------------------------------------------------------
估计你的测试代码,在某个地方启动了事务
不允许事务嵌套
当前线程已经有一个事务关联了。

        

热点排行