0
votes

Exception :Error while committing the transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction 2017-08-19 16:51:28,120 WARN c.a.v.c.VerificationController Stack Trace :org.springframework.orm.jpa.JpaSystemException: Error while committing the transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:403) at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:226) at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerSynchronization.convertException(ExtendedEntityManagerCreator.java:492) at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerSynchronization.afterCommit(ExtendedEntityManagerCreator.java:465) at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCommit(TransactionSynchronizationUtils.java:134) at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerAfterCommit(TransactionSynchronizationUtils.java:122) at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCommit(AbstractPlatformTransactionManager.java:944) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:781) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:710) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:512) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:298) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:182) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:182) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:134) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:182) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:182) at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:58) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) at com.sun.proxy.$Proxy1019.save(Unknown Source) at com.aadhaar.verify.controller.VerificationController.Verification(VerificationController.java:296) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 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:208) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:135) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:859) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:769) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:86) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:970) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:904) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:971) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:874) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:848) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:350) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:265) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:199) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:115) at org.springframework.boot.web.servlet.support.ErrorPageFilter.access$000(ErrorPageFilter.java:59) at org.springframework.boot.web.servlet.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:90) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:108) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3654) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3620) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326) at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:196) at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203) at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71) at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2423) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2280) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2258) at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1626) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1586) at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270) at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348) at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333) at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54) at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41) at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:617) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:397) at weblogic.work.ExecuteThread.run(ExecuteThread.java:346) Caused by: javax.persistence.RollbackException: Error while committing the transaction at org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:75) at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:71) at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerSynchronization.afterCommit(ExtendedEntityManagerCreator.java:462) ... 109 more Caused by: java.sql.SQLException: The transaction is no longer active - status: 'Committed'. No further JDBC access is allowed within this transaction. at weblogic.jdbc.wrapper.JTSConnection.checkIfRolledBack(JTSConnection.java:205) at weblogic.jdbc.wrapper.JTSConnection.checkConnection(JTSConnection.java:216) at weblogic.jdbc.wrapper.JTSConnection.commit(JTSConnection.java:683) at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.commit(AbstractLogicalConnectionImplementor.java:81) at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:221) at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68) ... 110 more

Not Working Controller :

@RestController
@RequestMapping("/demographic")
@SuppressWarnings("rawtypes")
public class VerificationController {

    @Autowired
    EntityManager entityManager;

    public final Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    private UserRepository userRepo;
    @Autowired
    private RoleRepository roleRepo;
    @Autowired
    private VerificationRepository veRepository;

    @PostMapping(value = "/validate")
    @ResponseBody
    public ResponseDTO Verification(@RequestBody VerificationModel verificationModel) throws IOException {
        logger.info("-----Start of Method------ ");
        logger.info("verify");
        logger.debug("Request  :" + verificationModel);

        ResponseDTO responseDTO = new ResponseDTO();
        VerificationLog verificationLog = new VerificationLog();

        // General Elements
        verificationLog.setAadharNumber("290567459087");
        verificationLog.setVerificationType("pi");
        verificationLog.setVerifiedBy("superadmin");
        verificationLog.setUploadedDate(new Date());
        verificationLog.setIsBulkUpload(false);

        // Default Values
        verificationLog.setAge(0);
        verificationLog.setMatchPercentage(0);

        logger.debug("Request to be Added :" + verificationLog);
        VerificationLog verificationLog1 = veRepository.save(verificationLog);

        logger.debug("Request to be Added :" + verificationLog1);

Working Controller :

@RestController
@RequestMapping("/user")
@SuppressWarnings("rawtypes")
public class UserController {

    @Autowired
    EntityManager entityManager;

    public final Logger logger = LoggerFactory.getLogger(this.getClass());

@PostMapping(value = "/createadmin")
    @ResponseBody
    public ResponseDTO createAdminUser(@RequestBody User user) {
        logger.info("-----Start of Method------ ");
        logger.info("createadmin");
        logger.debug("Request  :" + user);
        ResponseDTO responseDto = new ResponseDTO();

        try {
            Object object = userRepo.findAdminUser(user.getUserName());
            if (object == null) {
                user.setIsActive(true);
                User createdUser = userRepo.save(user);         

                UserRole newUserRole = new UserRole();
                newUserRole.setUserName(createdUser.getUserName());
                newUserRole.setRole("ROLE_ADMIN");
                roleRepo.save(newUserRole);

                responseDto.setResult("Created");

                List list = userRepo.findAllAdminUsers();
                List<UserResponseDTO> admins = new ArrayList<UserResponseDTO>();
                for (int i = 0; i < list.size(); i++) {
                    Object[] row = (Object[]) list.get(i);
                    admins.add(new UserResponseDTO((String) row[0], (String) row[1], (Boolean) row[2]));
                }
                responseDto.setData(admins);
            } else {
                responseDto.setResult("Already Exists");
            }
        } catch (Exception e) {
            logger.error("Exception :" + e.getMessage());
            logger.warn("Stack Trace :" + e.getStackTrace());
        }
        logger.debug("Response :" + responseDto);
        logger.info("-----End of Method------ ");
        return responseDto;
    }

BeanConfig :

@Configuration
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
public class BeanConfig {

    @SuppressWarnings("deprecation")
    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean lemb = new LocalContainerEntityManagerFactoryBean();
        lemb.setDataSource(getJndiObjectFactoryBean());
        lemb.setJpaVendorAdapter(jpaVendorAdapter());
        lemb.setJpaDialect(new HibernateJpaDialect());
        // lemb.setJ
        Properties prop = new Properties();
        prop.put(org.hibernate.cfg.Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT);
        // prop.put(org.hibernate.cfg.annotations.IdBagBinder.)
        lemb.setJpaProperties(prop);
        lemb.setPackagesToScan(new String[] { ("com.aadhaar.verify.model"), ("com.aadhaar.verify.response") });
        return lemb;

    }

    public JpaVendorAdapter jpaVendorAdapter() {
        HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
        jpaVendorAdapter.setShowSql(false);
        jpaVendorAdapter.setGenerateDdl(false);
        // jpaVendorAdapter.setDatabase(Database.MYSQL);
        return jpaVendorAdapter;
    }

    @Bean
    public DataSource getJndiObjectFactoryBean() {
        // ComboPooledDataSource datasource = new ComboPooledDataSource();;
        // try {
        // datasource.setDriverClass("oracle.jdbc.driver.OracleDriver");
        // } catch (PropertyVetoException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }

        // datasource.setMinPoolSize(5);
        // datasource.setMaxIdleTime(2000);
        // datasource.setMaxPoolSize(20);
        // datasource.setMaxStatements(2000);
        // return datasource;
        JndiObjectFactoryBean jobjFac = new JndiObjectFactoryBean();
        jobjFac.setJndiName("jdbc/AppzillonServerDS");
        try {
            jobjFac.setResourceRef(true);
            jobjFac.setProxyInterface(DataSource.class);
            jobjFac.afterPropertiesSet();
        } catch (IllegalArgumentException | NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();        
        }
        return (DataSource) jobjFac.getObject();
        /*
         * JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
         * DataSource dataSource =
         * dataSourceLookup.getDataSource("jdbc/AppzillonServerDS"); return
         * dataSource;
         */
    }
1
Where is located the class VerificationRepository ? which package?cralfaro
It is on the same project but different package . Please find it below com.aadhaar.verify.repository; - Repository Package com.aadhaar.verify.controller; - Controller PackageDeveloper Vertace
The key is here: The transaction is no longer active - status: Committed. No further JDBC access is allowed within this transaction. You're trying to perform some query while transaction is already commited.Xtreme Biker
I think your problem is with the DS to connect weblogic and your DB, and this property. prop.put(org.hibernate.cfg.Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.AFTER_STATEMENT)cralfaro

1 Answers

0
votes

Try adding this property

Properties prop = new Properties();
prop.put("hibernate.connection.release_mode", "auto");
prop.put("hibernate.connection.handling_mode", "DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT");