[英]org.hibernate.HibernateException: Unable to locate current JTA transaction
Good Morning to every one. 各位早上好。 I have a strange problem with hibernate and JTA Transactions. 我对休眠和JTA事务有一个奇怪的问题。 I have this code: 我有以下代码:
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);
}
}
Internally, the four steps uses 在内部,这四个步骤使用
Session session = super.getSession();
to find the transaction, but only the Step C fails at this point, and i dont know why. 找到交易,但只有步骤C在这一点上失败了,我不知道为什么。
The stackTrace is 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] ==
I have find the problem. 我发现了问题。
Method 1 ->@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
SubMethod 2-> @TransactionAttribute(TransactionAttributeType.SUPPORTS)
SubMethod 3-> @TransactionAttribute(TransactionAttributeType.SUPPORTS)
I do not know why, but this transaction structure does not work. 我不知道为什么,但是这种交易结构不起作用。 I need to put the transactions like this: 我需要这样的交易:
Method 1 ->@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
SubMethod 2-> @TransactionAttribute(TransactionAttributeType.REQUIRED)
SubMethod 3-> @TransactionAttribute(TransactionAttributeType.SUPPORTS)
Why the first option does not work? 为什么第一个选项不起作用?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.