在org.hibernate.internal.ExceptionConverterImpl.convertCommitException [英] at org.hibernate.internal.ExceptionConverterImpl.convertCommitException

查看:176
本文介绍了在org.hibernate.internal.ExceptionConverterImpl.convertCommitException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新其所有子表中的表及其引用的ID.但是在提交事务时,出现以下错误.

I am updating and Id of the table and its references in all its child tables. But while committing the transaction I got following error.

我尝试搜索,但未找到任何相关解决方案

I tried searching but not found any related solutions

我没有使用spring @transactional.在这里,我正在手动开始并提交事务.

I am not using spring @transactional. Here I am manually beginning and committing the transactions.

此外,当我执行相同的代码以减少5到10条记录时,我没有遇到这个问题.但是这次我要执行11K.

Also, I didn't face this issue when I executed the same code for fewer records as 5 to 10 . But this time I am executing for 11K.

public void updateAllCustWithSameCustIdAndAccNum() {
    EntityManager em = null;
    EntityManager em2 = null;
    EntityTransaction entityTransaction = null;
    EntityTransaction entityTransactionTwo = null;
    Long currentTimeStamp = System.currentTimeMillis();
    try{
        int flag;
        em = connectionService.getEm();
        entityTransaction = em.getTransaction();
        entityTransaction.begin();



        em2 = connectionServiceTwo.getEm();
        entityTransactionTwo = em2.getTransaction();
        entityTransactionTwo.begin();

        List<String> custHavingSameAccIdList = linkageFileRepository.getAllCustWithSameCustIdAndAccNum(em);

        /*custHavingSameAccIdList.add("a17b593eaf80264a3a0c12c3606220f06ce3d7b57fcbdce6df72b4cea7d9669c");
        custHavingSameAccIdList.add("a60830b39df5f2a20b41bd25c1da55728ffb24c144259231f1a2da5e61490e11");
        custHavingSameAccIdList.add("6274dd3438adacf524c61b7b53a946494388a8fdcbd6ada59bb4f2a258332f0b");*/

        if(custHavingSameAccIdList.size() > 0){
            List<LinkageFile> linkageCustList = linkageFileRepository.getNewCustId(custHavingSameAccIdList,em);

            Map<String, List<LinkageFile>> map2 = new HashMap<>();
            linkageCustList.forEach(object ->
                    map2.computeIfAbsent(object.getAccountNum(), k -> new ArrayList<>())
                            .add(object));



            //This query checks those account_number which has come multiple times with different customer_ids
            List<Object> ambigiousAccountNumList = linkageFileRepository.getAmbigiousAccountNum(custHavingSameAccIdList,em);
            for(Object object : ambigiousAccountNumList){
                Object[] objarr = (Object []) object;

                map2.remove(objarr[0]);
            }

            if(ambigiousAccountNumList!= null && ambigiousAccountNumList.size() > 0){
                linkageCustList = new ArrayList<>();
                Iterator iterator = map2.values().iterator();
                while (iterator.hasNext()){
                    linkageCustList.addAll((List<LinkageFile>) iterator.next());
                }
            }

            //switch off foreing checks
            flag = linkageFileRepository.switchForeignChecks(em,0);
            logger.debug("foreing check value : " + flag);
            String oldCustId = null;
            String newCustId = null;
            List<CboiCCLog> cboiCCLogList = new ArrayList<>();
            ObjectMapper objectMapper = new ObjectMapper();

            for(LinkageFile linkageFile  : linkageCustList){
                linkageFile.setDone(true);
                oldCustId = linkageFile.getAccountNum();
                newCustId = linkageFile.getCustomerId();

                List<Object> blockList = linkageFileRepository.getBlock(oldCustId,em);
                //handle this later
                List<Object> ticketList = linkageFileRepository.getTicket(oldCustId,em2);
                List<Object> tcktRspnList = linkageFileRepository.getTicketResponse(oldCustId,em2);
                List<Object> tcktComnList = linkageFileRepository.getTicketCommn(oldCustId,em2);
                List<Object> auditList = linkageFileRepository.getCustomerAudit(oldCustId,em);
                List<Object> customerImgList = linkageFileRepository.getCustomerImg(oldCustId,em);
                List<Object> custLedList = linkageFileRepository.getCustLedger(oldCustId,em);
                List<Object> custMissingList = linkageFileRepository.getCustMissingQue(oldCustId,em);
                List<Object> custOtpList = linkageFileRepository.getCustOtpTracker(oldCustId,em);
                List<Object> eventList = linkageFileRepository.getEvent(oldCustId,em);
                List<Object> loginHistList = linkageFileRepository.getLoginHist(oldCustId,em);
                List<Object> mgmMappingList = linkageFileRepository.getMgmMapping(oldCustId,em);
                List<Object> poinList = linkageFileRepository.getPoint(oldCustId,em);
                List<Object> redemptionList = linkageFileRepository.getRedemption(oldCustId,em);
                List<Object> usernamePsswrdLogList = linkageFileRepository.getUsernamePsswrdLog(oldCustId,em);
                List<Object> topList = linkageFileRepository.getTxnOfferPoint(oldCustId,em);
                List<Object> txnList = linkageFileRepository.getTxn(oldCustId,em);
                List<Object> cardLedgList = linkageFileRepository.getCardLedger(oldCustId,em);
                List<Object> cardList = linkageFileRepository.getCard(oldCustId,em);
                List<Object> accLedgList = linkageFileRepository.getAccLedger(oldCustId,em);
                List<Object> accList = linkageFileRepository.getAcc(oldCustId,em);
                List<Object> custProfileList = linkageFileRepository.getCustProfile(oldCustId,em);
                List<Object> custList = linkageFileRepository.getCustomer(oldCustId,em);

                if(blockList.size() > 0 ){
                    addToLogList(cboiCCLogList,blockList,objectMapper,linkageFile,"BLOCK");
                    linkageFileRepository.updateBlock(oldCustId,newCustId,em);
                }
                // TODO: 12/31/2018  hdandle this 
                if(ticketList.size() > 0 ){
                    addToLogList(cboiCCLogList,ticketList,objectMapper,linkageFile,"TICKET");
                    linkageFileRepository.updateTicket(oldCustId,newCustId,em2);
                }
                if(tcktRspnList.size() > 0 ){
                    addToLogList(cboiCCLogList,tcktRspnList,objectMapper,linkageFile,"TICKET");
                    linkageFileRepository.updateTicketResponse(oldCustId,newCustId,em2);
                }
                if(tcktComnList.size() > 0 ){
                    addToLogList(cboiCCLogList,tcktComnList,objectMapper,linkageFile,"TICKET");
                    linkageFileRepository.updateTicketCommn(oldCustId,newCustId,em2);
                }
                if(auditList.size() > 0){
                    addToLogList(cboiCCLogList,auditList,objectMapper,linkageFile,"CUSTOMER_AUDIT_TABLE");
                    linkageFileRepository.updateCustomerAudit(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(customerImgList.size() > 0){
                    addToLogList(cboiCCLogList,customerImgList,objectMapper,linkageFile,"CUSTOMER_IMAGE");
                    linkageFileRepository.updateCustomerImg(oldCustId,newCustId,em);
                }
                if(custLedList.size() > 0){
                    addToLogList(cboiCCLogList,custLedList,objectMapper,linkageFile,"CUSTOMER_LEDGER");
                    linkageFileRepository.updateCustLedger(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(custMissingList.size() > 0){
                    addToLogList(cboiCCLogList,custMissingList,objectMapper,linkageFile,"CUSTOMER_MISSING_QUEUE");
                    linkageFileRepository.updateCustMissingQue(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(custOtpList.size() > 0){
                    addToLogList(cboiCCLogList,custOtpList,objectMapper,linkageFile,"CUSTOMER_OTP_TRACKER");
                    linkageFileRepository.updateCustOtpTracker(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(eventList.size() > 0){
                    addToLogList(cboiCCLogList,eventList,objectMapper,linkageFile,"EVENT");
                    linkageFileRepository.updateEvent(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(loginHistList.size() > 0){
                    addToLogList(cboiCCLogList,loginHistList,objectMapper,linkageFile,"LOGINHISTORY");
                    linkageFileRepository.updateLoginHist(oldCustId,newCustId,em,currentTimeStamp);
                }
                try {
                    if(mgmMappingList.size() > 0){
                        addToLogList(cboiCCLogList,mgmMappingList,objectMapper,linkageFile,"MGM_MAPPING");
                        linkageFileRepository.updateMgmMapping(oldCustId,newCustId,em);
                    }
                }catch (PersistenceException e) {
                    Throwable t = e.getCause();
                    while ((t != null) && !(t instanceof ConstraintViolationException)) {
                        t = t.getCause();
                    }
                    if (t instanceof ConstraintViolationException) {
                        e.printStackTrace();
                    }
                }

                if(poinList.size() > 0){
                    addToLogList(cboiCCLogList,poinList,objectMapper,linkageFile,"POINT");
                    linkageFileRepository.updatePoint(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(redemptionList.size() > 0){
                    addToLogList(cboiCCLogList,redemptionList,objectMapper,linkageFile,"REDEMPTION");
                    linkageFileRepository.updateRedemption(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(usernamePsswrdLogList.size() > 0){
                    addToLogList(cboiCCLogList,usernamePsswrdLogList,objectMapper,linkageFile,"USERNAME_PASSWORD_LOG");
                    linkageFileRepository.updateUsernamePsswrdLog(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(topList.size() > 0){
                    addToLogList(cboiCCLogList,topList,objectMapper,linkageFile,"TRANSACTION_OFFER_POINT");
                    linkageFileRepository.updateTxnOfferPoint(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(txnList.size() > 0){
                    addToLogList(cboiCCLogList,txnList,objectMapper,linkageFile,"TRANSACTOIN");
                    linkageFileRepository.updateTxn(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(cardLedgList.size() > 0){
                    addToLogList(cboiCCLogList,cardLedgList,objectMapper,linkageFile,"CARD_LEDGER");
                    linkageFileRepository.updateCardLedg(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(cardList.size() > 0){
                    addToLogList(cboiCCLogList,cardList,objectMapper,linkageFile,"CARD");
                    linkageFileRepository.updateCard(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(accLedgList.size() > 0){
                    addToLogList(cboiCCLogList,accLedgList,objectMapper,linkageFile,"ACCOUNT_LEDGER");
                    linkageFileRepository.updateAccLedg(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(accList.size() > 0){
                    addToLogList(cboiCCLogList,accList,objectMapper,linkageFile,"ACCOUNT");
                    linkageFileRepository.updateAcc(oldCustId,newCustId,em,currentTimeStamp);
                }
                if(custProfileList.size() > 0){
                    addToLogList(cboiCCLogList,custProfileList,objectMapper,linkageFile,"CUSTOMER_PROFILE");
                    linkageFileRepository.updateCustProfile(oldCustId,newCustId,em,currentTimeStamp);
                }

                try{
                    if(custList.size() > 0){
                        addToLogList(cboiCCLogList,custList,objectMapper,linkageFile,"CUSTOMER");
                        linkageFileRepository.updateCustomer(oldCustId,newCustId,em,currentTimeStamp);
                    }
                }
                catch (PersistenceException e) {
                    Throwable t = e.getCause();
                    while ((t != null) && !(t instanceof ConstraintViolationException)) {
                        t = t.getCause();
                    }
                    if (t instanceof ConstraintViolationException) {
                        e.printStackTrace();
                    }
                }
                em.merge(linkageFile);
            }
            for(CboiCCLog cboic : cboiCCLogList){
                em.persist(cboic);
            }
        }

        flag = linkageFileRepository.switchForeignChecks(em,1);
        logger.debug("foreing check value : " + flag);

        if(entityTransactionTwo.isActive()){
            entityTransactionTwo.commit();
        }

        if (entityTransaction.isActive()) {
            entityTransaction.commit();
        }

    }catch (Exception e){
        e.printStackTrace();
        if (entityTransaction != null) {
            entityTransaction.rollback();
        }
        if (entityTransactionTwo != null) {
            entityTransactionTwo.rollback();
        }
    }
    finally {
        em.close();
        em2.close();
    }

}

推荐答案

WAL(预写日志)非常大,数据库可能会遇到Stackoverflow-Exception.

The WAL (Write ahead log) is huge and the database might run into an Stackoverflow-Exception.

要么增加数据库服务器上的WAL,要么将工作分成更小的部分.

Either you increase the WAL on the database server or you chunk the work into smaller pieces.

这篇关于在org.hibernate.internal.ExceptionConverterImpl.convertCommitException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆