Resource.java
@RequestMapping(value = "/updateDetails", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasRole('" + ROLE_BPM_EAUTH_WF_CLIENT + "')")
public ResponseEntity<UpdateStatus> updateDetails(@RequestBody updateRequest updateRequest) throws ServiceException {
UpdateStatus response = null;
try{
response = controlService.updateDetails(updateRequest);
}catch (ControlServiceException controlServiceException) {
if(ErrorCodes.ERROR_CODE.FAILED_TO_UPDATE_DETAILS.getCode().equals(controlServiceException.getErrorCode())
|| ErrorCodes.ERROR_CODE.FAILED_TO_UPDATE_DETAILS_STALE_DATA_ISSUE.getCode().equals(controlServiceException.getErrorCode())) {
final int maxRetryCount = controlService.getMaxRetryCountFromConfig();
response = retryUpdateDetails(updateRequest, 1, maxRetryCount);
} else{
throw controlServiceException;
}
}
return new ResponseEntity<>(response, HttpStatus.OK);
}
Service.java
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { ServiceException.class })
public UpdateStatus updateDetails(UpdateRequest updateRequest) throws ServiceException {
Object object = updateRequest.getObject();
updateDetailActions(updateRequest);
return InformationTransformer.transformStatus(object, true);
}
private void updateDetailActions(updateRequest updateRequest) throws ServiceException {
DefaultDetails defaultDetails = null;
if (updateRequest.getEventType().equals(EventTypeEnum.A.getValue())) {
updateStatusToA(updateRequest);
}
Object object = updateRequest.getObject();
ObjectDetail localObjectDetail = objectDetailRepo.getObjectDetailsByCriteria(object);
ObjectDetail objectDetail = objectCreateHelper.createOrReplaceObjectDetails(updateRequest, localObjectDetail, object);
EventTypeEnum eventType = EventTypeEnum.getByName(updateRequest.getEventType());
Boolean isUpdateBSRequired = objectCreateHelper.isRESTCallRequired(updateRequest, localObjectDetail);
if(isUpdateBSRequired){
defaultDetails = objectCreateHelper.setBSDetails(objectDetail,object);
}
performEventRelatedUpdates(updateRequest, objectDetail, eventType);
try {
populateObjectCriticalityForEvents(updateRequest ,object, objectDetail);
} catch (ControlServiceException e) {
throw new ControlServiceException(ErrorCodes.ERROR_CODE.FAILED_TO_POPULATE_CRITICALITY, e);
} finally {
objectDetail = saveObjectDetails(objectDetail, object);
if(isUpdateBSRequired){
objectCreateHelper.updateBS(object, defaultDetails);
if(objectCreateHelper.isPUEnabled(object)){
performPU(object, objectDetail);
}
}
}
}
@Override
public ObjectDetail saveDetails(ObjectDetail objectDetail, Object object) throws ControlServiceException {
try {
return objectDetailRepo.saveDetail(objectDetail);
} catch (ObjectOptimisticLockingFailureException exception){
throw new ControlServiceException(ErrorCodes.ERROR_CODE.FAILED_TO_UPDATE_DETAILS_STALE_DATA_ISSUE, exception);
} catch (Exception ex) {
throw new ControlServiceException(ErrorCodes.ERROR_CODE.FAILED_TO_UPDATE_DETAILS, ex);
}
}
exception logs :
Exception occurred while saving Object as org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:413)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:227)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:43)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy282.saveekDetail(Unknown Source)
at com.ek.acp.service.ekcontrol.impl.ekControlServiceImpl.saveekDetails(ekControlServiceImpl.java:1184)
at com.ek.acp.service.ekcontrol.impl.ekControlServiceImpl.updateekDetailActions(ekControlServiceImpl.java:331)
at com.ek.acp.service.ekcontrol.impl.ekControlServiceImpl.updateekDetails(ekControlServiceImpl.java:276)
at sun.reflect.GeneratedMethodAccessor764.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
at com.ek.egsframework.persistence.serviceinterceptors.EGSTransactionInterceptor.executeService(EGSTransactionInterceptor.java:125)
at com.ek.egsframework.persistence.serviceinterceptors.EGSTransactionInterceptor.transactionWithoutEGSServiceMethod(EGSTransactionInterceptor.java:67)
at sun.reflect.GeneratedMethodAccessor155.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
at com.ek.egsframework.persistence.serviceinterceptors.ModuleManagerInterceptor.checkEGServiceAnnotation(ModuleManagerInterceptor.java:65)
at sun.reflect.GeneratedMethodAccessor165.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:58)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy348.updateekDetails(Unknown Source)
at com.ek.acp.controller.events.ekEventResource.updateekDetails(ekEventResource.java:108)
at com.ek.acp.controller.events.ekEventResource$$FastClassBySpringCGLIB$$c1e0a006.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:718)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:68)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:654)
at com.ek.acp.controller.events.ekEventResource$$EnhancerBySpringCGLIB$$d7109e94.updateekDetails(<generated>)
at sun.reflect.GeneratedMethodAccessor777.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.ek.web.filter.RequestMDCLogger.doFilter(RequestMDCLogger.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.codahale.metrics.servlet.AbstractInstrumentedFilter.doFilter(AbstractInstrumentedFilter.java:104)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:242)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.springframework.web.multipart.support.MultipartFilter.doFilterInternal(MultipartFilter.java:118)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.ek.authentication.jwt.JwtAuthenticationFilter.successfulAuthentication(JwtAuthenticationFilter.java:188)
at com.ek.authentication.jwt.JwtAuthenticationFilter.doAuthenticate(JwtAuthenticationFilter.java:104)
at com.ek.authentication.jwt.JwtAuthenticationFilter.doFilter(JwtAuthenticationFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.ek.security.ping.EGSPingAuthenticationFilter.doFilterInternal(EGSPingAuthenticationFilter.java:114)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.ek.web.filter.PingRequestFilter.doFilterInternal(PingRequestFilter.java:107)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:111)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:207)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:120)
at org.springframework.boot.context.web.ErrorPageFilter.access$000(ErrorPageFilter.java:61)
at org.springframework.boot.context.web.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:95)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:113)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)
at org.jboss.web.rewrite.RewriteValve.invoke(RewriteValve.java:466)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:854)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:656)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:993)
at sun.reflect.GeneratedMethodAccessor440.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:344)
at com.sun.proxy.$Proxy196.flush(Unknown Source)
at sun.reflect.GeneratedMethodAccessor440.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:293)
at com.sun.proxy.$Proxy195.flush(Unknown Source)
at com.ek.egsframework.persistence.repository.AbstractJPARepository.flush(AbstractJPARepository.java:120)
at com.ek.egsframework.persistence.repository.AbstractJPARepository.makePersistent(AbstractJPARepository.java:79)
at com.ek.acp.repository.ekcontrol.impl.ekDetailRepoImpl.saveekDetail(ekDetailRepoImpl.java:86)
at sun.reflect.GeneratedMethodAccessor763.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
... 151 more
<!-- tomcat-app-datasource.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd">
<import resource="classpath:META-INF/spring/jpa-persistence-conf.xml"/>
<import resource="classpath:META-INF/spring/jdbc-persistence-conf.xml"/>
<bean id="appDataSource" p:username="username" p:password="password"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="oracle.jdbc.driver.OracleDriver" p:url="url"/>
<!--<bean class="com.zaxxer.hikari.HikariConfig" id="hikariConfig"
p:driverClassName="org.h2.Driver"
p:jdbcUrl="jdbc:h2:mem:egspring;MODE=Oracle;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE;MVCC=TRUE"/>-->
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"
depends-on="atomikosTransactionManager,atomikosUserTransaction">
<property name="transactionManager" ref="atomikosTransactionManager"/>
<property name="userTransaction" ref="atomikosUserTransaction"/>
</bean>
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown" value="false"/>
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
<property name="transactionTimeout" value="30000"/>
</bean>
<!-- <bean id="appDataSource"
class="com.zaxxer.hikari.HikariDataSource">
<constructor-arg ref="hikariConfig"/>
</bean>-->
<bean parent="dataSource" id="defaultJDBCDataSource"/>
<bean id="dataSource" primary="true"
class="com.emirates.egsframework.persistence.datasources.DatasourceRouter"
lazy-init="true">
<property name="targetDataSources">
<map>
<entry key="RODS" value-ref="appDataSource"/>
<entry key="RWDS" value-ref="appDataSource"/>
<entry key="XADS" value-ref="appDataSource"/>
</map>
</property>
<property name="defaultTargetDataSource" ref="appDataSource"/>
</bean>
<bean id="securityDatasource"
class="com.emirates.egsframework.persistence.datasources.DatasourceRouter"
lazy-init="true">
<property name="targetDataSources">
<map>
<entry key="RODS" value-ref="appDataSource"/>
<entry key="RWDS" value-ref="appDataSource"/>
<entry key="XADS" value-ref="appDataSource"/>
</map>
</property>
<property name="defaultTargetDataSource" ref="appDataSource"/>
</bean>
<bean id="auditDatasource"
class="com.emirates.egsframework.persistence.datasources.DatasourceRouter"
lazy-init="true">
<property name="targetDataSources">
<map>
<entry key="RODS" value-ref="appDataSource"/>
<entry key="RWDS" value-ref="appDataSource"/>
<entry key="XADS" value-ref="appDataSource"/>
</map>
</property>
<property name="defaultTargetDataSource" ref="appDataSource"/>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
parent="abstractEntityManagerFactory" lazy-init="true">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="oracle_pu"/>
</bean>
<bean id="defaultEntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
parent="abstractEntityManagerFactory" lazy-init="true">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="oracle_pu"/>
</bean>
<util:map id="entityMangerFactoryMap">
<entry key="audit" value-ref="entityManagerFactory"/>
<entry key="securityService" value-ref="entityManagerFactory"/>
</util:map>
<!-- <alias name="defaultEntityManagerFactory" alias="entityManagerFactory"/>-->
<util:properties id="jpaProperties">
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.transaction.manager_lookup_class">
com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
</prop>
<prop key="hibernate.transaction.factory_class">
org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
</prop>
<!--<prop key="hibernate.transaction.factory_class">org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory</prop>
<prop key="hibernate.connection.autocommit">false</prop>-->
<!--<prop key="hibernate.transaction.jta.platform">com.atomikos.icatch.jta.hibernate4.AtomikosPlatform</prop>-->
<!--<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform</prop>-->
<prop key="hibernate.transaction.flush_before_completion">false</prop>
<prop key="hibernate.transaction.auto_close_session">true</prop>
<prop key="hibernate.current_session_context_class">jta</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
</util:properties>
</beans>
有时会连续不断出现以下错误,并且在保存其他相同类型的对象时效果很好: 将其另存为org.springframework.dao.InvalidDataAccessApiUsageException时发生异常:正在进行任何事务;嵌套异常是javax.persistence.TransactionRequiredException:没有事务正在进行
答案 0 :(得分:0)
当您在非事务上下文中执行数据库事务时,通常会发生此异常。对于执行数据库事务的方法,您可以在spring中使用@Transactional批注。有关交易管理的详细信息,请参阅 https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/transaction.html
答案 1 :(得分:0)
您如何访问Service
课程?对于要创建的Spring事务,您需要通过那里的Spring Application Context访问您的类,然后而不是通过例如创建新实例(new Service()
无效),也不会通过变量访问实例或此类(即使该变量最初是由spring设置的)