我收到了ResourceException:交易未激活

时间:2016-05-24 05:40:19

标签: java hibernate jboss database-connection jboss5.x

我正在使用Jboss版本5.2.0.GA,并且在使用hql更新数据库中的记录状态时,我没有激活事务处理。 数据库连接没有用完,其他请求由DB完成,我相信交易已过期!

如果在transaction-jboss-beans.xml中增加300,它会有帮助吗?

2016-05-23 10:37:11,722  - ERROR - TestDAO.java : updateRecord (490) -  updateRecord() Exception Message Cannot open connection
org.hibernate.exception.GenericJDBCException: Cannot open connection
  at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
  at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
  at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
  at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
  at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:145)
  at org.hibernate.persister.entity.AbstractEntityPersister.getDatabaseSnapshot(AbstractEntityPersister.java:1034)
  at org.hibernate.engine.StatefulPersistenceContext.getDatabaseSnapshot(StatefulPersistenceContext.java:268)
  at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:212)
  at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:534)
  at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:102)
  at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:92)
  at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:537)
  at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:529)
  at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:241)
  at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:302)
  at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:246)
  at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:195)
  at org.hibernate.engine.Cascade.cascade(Cascade.java:154)
  at org.hibernate.engine.Cascade.cascade(Cascade.java:121)
  at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.cascadeOnUpdate(DefaultSaveOrUpdateEventListener.java:379)
  at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:351)
  at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:245)
  at org.hibernate.event.def.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:56)
  at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:92)
  at org.hibernate.impl.SessionImpl.fireUpdate(SessionImpl.java:594)
  at org.hibernate.impl.SessionImpl.update(SessionImpl.java:582)
  at com.abc.xyz.dao.SendSmsDAO.updateSendSms(SendSmsDAO.java:479)
  at com.abc.xyz.transport.smpp.SMPPTransport.submitShortMessages(SMPPTransport.java:809)
  at com.abc.xyz.transport.smpp.SMPPTransport.submit(SMPPTransport.java:647)
  at com.abc.xyz.listeners.SendSmsMDB.onMessage(SendSmsMDB.java:202)
  at sun.reflect.GeneratedMethodAccessor845.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.jboss.invocation.Invocation.performCall(Invocation.java:386)
  at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(MessageDrivenContainer.java:518)
  at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:156)
  at org.jboss.ejb.plugins.MessageDrivenInstanceInterceptor.invoke(MessageDrivenInstanceInterceptor.java:115)
  at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:63)
  at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:121)
  at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:350)
  at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
  at org.jboss.ejb.plugins.RunAsSecurityInterceptor.process(RunAsSecurityInterceptor.java:139)
  at org.jboss.ejb.plugins.RunAsSecurityInterceptor.invoke(RunAsSecurityInterceptor.java:103)
  at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
  at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:138)
  at org.jboss.ejb.MessageDrivenContainer.internalInvoke(MessageDrivenContainer.java:420)
  at org.jboss.ejb.Container.invoke(Container.java:1092)
  at sun.reflect.GeneratedMethodAccessor786.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
  at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
  at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
  at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
  at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
  at org.jboss.invocation.local.LocalInvoker$MBeanServerAction.invoke(LocalInvoker.java:169)
  at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:118)
  at org.jboss.invocation.InvokerInterceptor.invokeLocal(InvokerInterceptor.java:209)
  at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:195)
  at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:61)
  at org.jboss.ejb.plugins.inflow.MessageEndpointInterceptor.delivery(MessageEndpointInterceptor.java:249)
  at org.jboss.ejb.plugins.inflow.MessageEndpointInterceptor.invoke(MessageEndpointInterceptor.java:128)
  at org.jboss.proxy.ClientMethodInterceptor.invoke(ClientMethodInterceptor.java:74)
  at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:101)
  at $Proxy1791.onMessage(Unknown Source)
  at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:179)
  at org.jboss.jms.client.container.ClientConsumer.callOnMessageStatic(ClientConsumer.java:167)
  at org.jboss.jms.client.container.SessionAspect.handleRun(SessionAspect.java:879)
  at org.jboss.aop.advice.org.jboss.jms.client.container.SessionAspect_z_handleRun_1017119892.invoke(SessionAspect_z_handleRun_1017119892.java)
  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  at org.jboss.jms.client.container.ClosedInterceptor.invoke(ClosedInterceptor.java:172)
  at org.jboss.aop.advice.PerInstanceInterceptor.invoke(PerInstanceInterceptor.java:86)
  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
  at org.jboss.jms.client.delegate.ClientSessionDelegate.run(ClientSessionDelegate.java)
  at org.jboss.jms.client.JBossSession.run(JBossSession.java:199)
  at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:236)
  at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:205)
  at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:260)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  at java.lang.Thread.run(Thread.java:662)
Caused by: org.jboss.util.NestedSQLException: Transaction is not active: tx=TransactionImple < ac, BasicAction: a1c162a:994a:5742b99a:169b status: ActionStatus.ABORTED >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: a1c162a:994a:5742b99a:169b status: ActionStatus.ABORTED >)
  at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:95)
  at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:91)
  at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
  ... 78 more
Caused by: javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: a1c162a:994a:5742b99a:169b status: ActionStatus.ABORTED >
  at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:413)
  at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:496)
  at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:941)
  at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89)
  ... 80 more

此致 Nithesh

2 个答案:

答案 0 :(得分:0)

你能发布你的行代码吗?我不知道你是否使用注释来控制事务,所以在你做合并之前使用entityManager.getTransaction.begin()可以解决问题。

答案 1 :(得分:0)

我没有使用Jboss交易,我使用的是hibernate交易,请找到下面的代码。

public void persistStatus(Status transientInstance){
        logger.debug("persisting into DB");
        org.hibernate.Transaction transaction = null;
        try
        {
            openSession();
            transaction = session.beginTransaction();

            session.persist(transientInstance);
            transaction.commit();   

            logger.debug("persist successfully ");
        }
        catch (HibernateException re){
            logger.error("Exception while inserting status "+re);

            if(transaction!=null && transaction.isActive())
                transaction.rollback();
            closeActiveSession();
            throw re;
        }finally{
            if (session != null && session.isOpen()) {
                session.clear();
                session.close();
            }
        }   
}

我认为Jboss内部处理交易?