org.hibernate.HibernateException:无法找到当前的JTA事务

时间:2016-08-26 16:06:51

标签: java hibernate transactions

每个人的早安。我对hibernate和JTA事务有一个奇怪的问题。 我有这段代码:

class MyClass{

private Adjustment adjustment = null;

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void processRecordMassive(List<File> fileData) throws BusinessException {

    //STEP A
    Map<String, Elemnts> lElements = this.fillMapElements(setSerialElement); // WORKS FINE

    //STEP B
    Warehouse warehouseTargetVO = 
    this.getWarehouse
    (sWareHouseTargetCode, adjustment.getCountry().getId().longValue()); //WORKS FINE

    //STEP B
    Long idAdjustment = 
    this.createAdjustment
    (UtilsBusiness.copyObject(AdjustmentVO.class, this.adjustment), this.getUploadFile().getUser().getId()); //WORKS FINE

    //STEP C
    this.adjustment = this.getAdjustmentByID(idAdjustment); // DOESN'T WORK org.hibernate.HibernateException: Unable to locate current JTA transaction 

}

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Map<String, WarehouseElement> fillMapElements(Set<String> setSerialElement) throws DAOServiceException, DAOSQLException{
    return warehouseElementDAO.getWarehouseElementBySerialActiveMassive(setSerialElement, this.getUploadFile().getCountry().getId());
}

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Warehouse getWarehouse(String sWHTargetCode, long longValue) throws DAOServiceException, DAOSQLException {
    return daoWarehouse.getWarehouseByCodeAndByCountry(sWHTargetCode, adjustment.getCountry().getId().longValue());
}

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Long createAdjustment(AdjustmentVO copyObject, Long id) throws BusinessException {
    return businessAdjustment.createAdjustment(copyObject, id);
}

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Adjustment getAdjustmentByID(Long idAdjustment) throws BusinessException {
    return businessAdjustment.getAdjustmentByID(idAdjustment);
}

}

在内部,这四个步骤使用

Session session = super.getSession();

找到交易,但此时只有步骤C失败,我不知道为什么。

stackTrace是

2016-08-26 12:45:55,538 FATAL co.com.app.sdii.ejb.business.BusinessBase.manageException(156) EJB Exception: : org.hibernate.HibernateException: Unable to locate current JTA transaction
    at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:88)
    at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:695)
    at co.com.app.sdii.persistence.hibernate.ConnectionFactory.getSession(ConnectionFactory.java:27)
    at co.com.app.sdii.persistence.dao.BaseDao.getSession(BaseDao.java:90)
    at co.com.app.sdii.persistence.dao.stock.impl.AdjustmentDAO.getAdjustmentByID(AdjustmentDAO.java:481)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37)
    at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:55)
    at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy226.getAdjustmentByID(Unknown Source)
    at co.com.app.sdii.persistence.dao.stock.impl.AdjustmentDAOLocal_as6iu7_AdjustmentDAOLocalImpl.getAdjustmentByID(AdjustmentDAOLocal_as6iu7_AdjustmentDAOLocalImpl.java:326)
    at co.com.app.sdii.ejb.business.stock.impl.AdjustmentBusinessBean.getAdjustmentByID(AdjustmentBusinessBean.java:169)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37)
    at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:55)
    at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy224.getAdjustmentByID(Unknown Source)
    at co.com.app.sdii.ejb.business.stock.impl.AdjustmentBusinessBean_h53llh_AdjustmentBusinessBeanLocalImpl.getAdjustmentByID(AdjustmentBusinessBean_h53llh_AdjustmentBusinessBeanLocalImpl.java:1251)
    at co.com.app.sdii.ejb.business.file.impl.stock.FileProcessorLoadMassiveSerializedElementsAdjustmentTransfer.getAdjustmentByID(FileProcessorLoadMassiveSerializedElementsAdjustmentTransfer.java:460)
    at co.com.app.sdii.ejb.business.file.impl.stock.FileProcessorLoadMassiveSerializedElementsAdjustmentTransfer.processRecordMassive(FileProcessorLoadMassiveSerializedElementsAdjustmentTransfer.java:396)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37)
    at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:55)
    at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy218.processRecordMassive(Unknown Source)
    at co.com.app.sdii.ejb.business.file.impl.stock.FileProcessorLoadMassiveSerializedElementsAdjustmentTransfer_4lp6tx_FileProcessorLoadMassiveSerializedElementsAdjustmentTransferLocalImpl.processRecordMassive(FileProcessorLoadMassiveSerializedElementsAdjustmentTransfer_4lp6tx_FileProcessorLoadMassiveSerializedElementsAdjustmentTransferLocalImpl.java:729)
    at co.com.app.sdii.ejb.business.file.ClientBasicFileProcessorMassive.processFile(ClientBasicFileProcessorMassive.java:80)
    at co.com.app.sdii.ejb.business.file.impl.FileProcessorBusinessBean.processFiles(FileProcessorBusinessBean.java:101)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37)
    at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:55)
    at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy184.processFiles(Unknown Source)
    at co.com.app.sdii.ejb.business.file.impl.FileProcessorBusinessBean_xhn0dd_FileProcessorBusinessBeanRemoteImpl.processFiles(FileProcessorBusinessBean_xhn0dd_FileProcessorBusinessBeanRemoteImpl.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:73)
    at com.sun.proxy.$Proxy97.processFiles(Unknown Source)
    at co.com.app.sdii.jobs.work.FileProcessorWork.run(FileProcessorWork.java:30)
    at weblogic.work.j2ee.J2EEWorkManager$WorkWithListener.run(J2EEWorkManager.java:183)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
; nested exception is: org.hibernate.HibernateException: Unable to locate current JTA transaction] ==

1 个答案:

答案 0 :(得分:0)

我找到了问题。

Method 1 ->@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
        SubMethod 2-> @TransactionAttribute(TransactionAttributeType.SUPPORTS)
            SubMethod 3-> @TransactionAttribute(TransactionAttributeType.SUPPORTS)

我不知道为什么,但这种交易结构不起作用。 我需要像这样进行交易:

Method 1 ->@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
        SubMethod 2-> @TransactionAttribute(TransactionAttributeType.REQUIRED)
            SubMethod 3-> @TransactionAttribute(TransactionAttributeType.SUPPORTS)

为什么第一个选项不起作用?