代码之家  ›  专栏  ›  技术社区  ›  Mahmoud Saleh

我怎样才能找到死亡的原因javax.transaction.RollbackException?

  •  11
  • Mahmoud Saleh  · 技术社区  · 6 年前

    我正在使用 正在运行 爪哇6

    数据库:Microsoft SQL Server 2012

    有时,当我尝试使用以下代码更新实体时:

    this.transaction.begin();
    // lots of lines of code here before the merge
    merge(carentrypermitrequest);
    this.transaction.commit(); // exception here
    

    我得到以下例外:

    javax.transaction.RollbackException
        at com.ibm.tx.jta.impl.TransactionImpl.stage3CommitProcessing(TransactionImpl.java:1268)
        at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1042)
        at com.ibm.tx.jta.impl.TransactionImpl.commit(TransactionImpl.java:963)
        at com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:439)
        at com.ibm.tx.jta.impl.TranManagerSet.commit(TranManagerSet.java:191)
        at com.ibm.ws.tx.jta.UserTransactionImpl.commit(UserTransactionImpl.java:302)
        at com.dataserve.mci.bean.license.CarEntryPermitRequestBean.completeAction(CarEntryPermitRequestBean.java:1525)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:611)
        at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:328)
        at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:341)
        at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
        at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
        at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
        at com.sun.faces.facelets.el.TagMethodExpression.invoke(Unknown Source)
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(Unknown Source)
        at com.sun.faces.application.ActionListenerImpl.processAction(Unknown Source)
        at org.primefaces.application.DialogActionListener.processAction(DialogActionListener.java:45)
        at javax.faces.component.UICommand.broadcast(Unknown Source)
        at javax.faces.component.UIViewRoot.broadcastEvents(Unknown Source)
        at javax.faces.component.UIViewRoot.processApplication(Unknown Source)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(Unknown Source)
        at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(Unknown Source)
        at javax.faces.webapp.FacesServlet.service(Unknown Source)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
        at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
        at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:100)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
        at com.filenet.ae.toolkit.server.servlet.filter.PostprocessorFilter.doFilter(PostprocessorFilter.java:38)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
        at com.filenet.ae.toolkit.server.servlet.filter.ContainerBasedFilter.doFilter(ContainerBasedFilter.java:218)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
        at com.filenet.ae.toolkit.server.servlet.filter.PreprocessorFilter.doFilter(PreprocessorFilter.java:91)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
        at com.filenet.ae.toolkit.server.servlet.filter.SecurityPluginFilter.doFilter(SecurityPluginFilter.java:202)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
        at com.filenet.ae.toolkit.server.servlet.filter.ThreadLocalCleanupFilter.doFilter(ThreadLocalCleanupFilter.java:50)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
        at com.dataserve.common.CompatibleFilter.doFilter(CompatibleFilter.java:53)
        at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
        at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
        at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:964)
        at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1104)
        at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3901)
        at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:981)
        at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:287)
        at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
        at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
        at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
        at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
        at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
        at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
        at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
        at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
        at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1865)
    

    protected SessionFactory getSessionFactory() {
            try {
                return (SessionFactory) new InitialContext().lookup("SessionFactory");
            } catch (Exception e) {
                log.error("Could not locate SessionFactory in JNDI", e);
                throw new IllegalStateException("Could not locate SessionFactory in JNDI");
            }
        }
    

    我就是这样得到这笔交易的:

    public final UserTransaction transaction = getUserTransaction();
    
    protected UserTransaction getUserTransaction() {
            try {
                return (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
            } catch (NamingException e) {
                e.printStackTrace();
                System.err.println("Could not locate UserTransaction in JNDI" + e.getMessage());
                throw new IllegalStateException("Could not locate UserTransaction in JNDI");
            }
        }
    

    以下是合并方法:

    public CarEntryPermitRequest merge(CarEntryPermitRequest detachedInstance) {
                try {
                    CarEntryPermitRequest result = (CarEntryPermitRequest) sessionFactory.getCurrentSession()
                            .merge(detachedInstance);
                    return result;
                } catch (RuntimeException re) {
                    throw re;
                }
            }
    

    以及 completeAction()

    public void completeAction() {
    
            try {
    
                Map fields = new HashMap();
    
                RequestContext requestContext = RequestContext.getCurrentInstance();
                RequestContext.getCurrentInstance().addCallbackParam("isValid", Boolean.valueOf(true));
    
                
                this.transaction.begin();
    
                if (stepNumber == null) {
    
                    if (numberOfUploadedFiles < 2) {
                        addErrorMessage("error1", null, true);
                        return;
                    }
                    requestContext.addCallbackParam("step", new Integer(1));
                    requestContext.addCallbackParam("isValid2", true);
    
                    if (carentrypermitrequest == null)
                        carentrypermitrequest = new CarEntryPermitRequest();
    
                    carentrypermitrequest.setRequesterUserName(loggedInUserId);
                    carentrypermitrequest.setRequesterName(empName);
                    carentrypermitrequest.setRequesterDepartmentName(empDept);
                    carentrypermitrequest.setRequesterMobile(empMobile);
                    carentrypermitrequest.setRequesterEmail(empEmail);
                    carentrypermitrequest.setRequestDate(new Date());
                    carentrypermitrequest.setRequestStatus(CarEntryPermitRequestStatusEnum.PENDING.getValue());
    
                    if (destination == null) {
    
                        addErrorMessage("error2", null, true);
                        requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                        requestContext.addCallbackParam("isValid2", false);
                        this.transaction.commit();
                        return;
                    }
    
                    if (empName == null || empName.equals("")) {
    
                        addErrorMessage("error3", null, true);
                        requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                        requestContext.addCallbackParam("isValid2", false);
                        this.transaction.commit();
                        return;
                    }
    
                    if (empMobile == null || empMobile.equals("")) {
    
                        addErrorMessage("error4", null, true);
                        requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                        requestContext.addCallbackParam("isValid2", false);
                        this.transaction.commit();
                        return;
                    }
    
                    if (empBuild.equals("error5")) {
                        addErrorMessage("error6", null, true);
                        requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                        requestContext.addCallbackParam("isValid2", false);
                        this.transaction.commit();
                        return;
                    }
    
                    try {
                        if (carcategoryvalue == -1 || carcategoryvalue == null || cartypevalue == null
                                || cartypevalue == 0) {
                            addErrorMessage("error7", null,
                                    true);
                            requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                            requestContext.addCallbackParam("isValid2", false);
                            this.transaction.commit();
                            return;
                        }
                    } catch (Exception e) {
                        AppLogger.Log(e);
                        addErrorMessage("error8", null, true);
                        requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                        this.transaction.commit();
                        return;
                    }
    
                    if (plateNumerSplited[0].trim().equals("") || plateNumerSplited[1].trim().equals("")) {
                        addErrorMessage("error9", null, true);
                        requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                        requestContext.addCallbackParam("isValid2", false);
                        this.transaction.commit();
                        return;
                    }
    
                    platenumber = getPlateString(plateNumerSplited);
    
                    if (carentrypermitrequesthome.isPlateHasPendingRequest(platenumber)) {
                        addErrorMessage("error10", null,
                                true);
                        requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                        requestContext.addCallbackParam("isValid2", false);
                        this.transaction.commit();
                        return;
                    }
    
                    if (destination.equals(DESTINATION_EMPLOYEE)) {
    
                        IoEmployees employee = ioemployeeHome.findByUserId(loggedInUserId);
                        if (employee != null) {
                            if (employee.getEmpMobile() == null || employee.getEmpMobile().trim().length() == 0) {
                                employee.setEmpMobile(empMobile);
                                ioemployeeHome.merge(employee);
                            }
                            carentrypermitrequest.setEmployee(employee);
                        }
                        carentrypermitrequest.setPlatenumber(platenumber);
                        if (StringUtils.isNotBlank(employeeNumber))
                            carentrypermitrequest.setEmployeeNumber(Integer.parseInt(employeeNumber.trim()));
                        if (StringUtils.isNotBlank(empExt))
                            carentrypermitrequest.setExt(Integer.parseInt(empExt.trim()));
    
                        CarType cartypeobj = cartypehome.findById(cartypevalue);
                        carentrypermitrequest.setCartypeId(cartypeobj);
                        carentrypermitrequest.setPermissioncase("under process");
                        CarCategory carcategoryobj = carcategoryehome.findById(carcategoryvalue);
                        carentrypermitrequest.setCarcategoryId(carcategoryobj);
    
                        CarColor carcolorobj = carcolorhome.findById(carcolorvalue);
                        carentrypermitrequest.setCarcolorId(carcolorobj);
                        carentrypermitrequest.setCarmodel(model);
                        carentrypermitrequest.setNotes(notes);
                        permitRequestDate = permitRequestDate.replace("/", "");
                        carentrypermitrequest.setPermitRequestDate(new Integer(permitRequestDate));
    
                        carentrypermitrequest.setEmpbuilding(empBuild);
    
                        carentrypermitrequesthome.attachDirty(carentrypermitrequest);
                        this.transaction.commit();
                        requestId = carentrypermitrequest.getCarentrypermitrequestId();
                        String subject = "aaaaaaaa  " + empName + " - bbbbbbbb : " + empMobile;
    
                        fields.put("F_Subject", subject);
                        fields.put("processType", PageCodeBase.PROCCESS_TYPES.CARENTRY.getCode());
                        fields.put("processID", carentrypermitrequest.getCarentrypermitrequestId());
                        fields.put("sendto", DESTINATION_EMPLOYEE);
                        fields.put("carentrypermitrequestID", carentrypermitrequest.getCarentrypermitrequestId());
                        fields.put("Building", empBuild.equals("المبنى الرئيسي") ? 1 : 2);
                        empMobileDisable = true;
                    }
    
                    if (destination.equals(DESTINATION_NOT_EMPLOYEE)) {
    
                        if (empDept == null || empDept.equals("")) {
                            addErrorMessage("aaaaaaaaaaa", null, true);
                            requestContext.addCallbackParam("isValid2", false);
                            this.transaction.commit();
                            return;
                        }
                        if (empNumber == null || empNumber.equals("")) {
                            addErrorMessage("vvvvvvvvvv ", null, true);
                            requestContext.addCallbackParam("isValid2", false);
                            this.transaction.commit();
                            return;
                        }
    
                        IoDepartments deptid = new IoDepartmentsHome().findByName(empDept);
    
                        carentrypermitrequest.setEmpdeptoutministry(deptid);
                        carentrypermitrequest.setEmpnameoutministry(empName);
                        carentrypermitrequest.setEmpnumoutministry(empNumber);
                        carentrypermitrequest.setEmpmobileoutministry(empMobile);
                        carentrypermitrequest.setEmpemailoutministry(empEmail);
                        carentrypermitrequest.setPlatenumber(platenumber);
                        CarType cartypeobj = cartypehome.findById(cartypevalue);
                        carentrypermitrequest.setCartypeId(cartypeobj);
                        carentrypermitrequest.setPermissioncase("تحت الأجراء");
                        CarCategory carcategoryobj = carcategoryehome.findById(carcategoryvalue);
                        carentrypermitrequest.setCarcategoryId(carcategoryobj);
                        CarColor carcolorobj = carcolorhome.findById(carcolorvalue);
                        carentrypermitrequest.setCarcolorId(carcolorobj);
                        carentrypermitrequest.setCarmodel(model);
                        carentrypermitrequest.setNotes(notes);
                        permitRequestDate = permitRequestDate.replace("/", "");
                        carentrypermitrequest.setPermitRequestDate(new Integer(permitRequestDate));
    
                        carentrypermitrequest.setEmpbuilding(empBuild);
    
                        carentrypermitrequesthome.attachDirty(carentrypermitrequest);
                        this.transaction.commit();
                        requestId = carentrypermitrequest.getCarentrypermitrequestId();
                        String subject = "gggggggggg  " + empName + " - tttttttttt: " + empMobile;
    
                        fields.put("F_Subject", subject);
                        fields.put("processType", PageCodeBase.PROCCESS_TYPES.CARENTRY.getCode());
                        fields.put("processID", carentrypermitrequest.getCarentrypermitrequestId());
                        fields.put("sendto", DESTINATION_NOT_EMPLOYEE);
                        fields.put("carentrypermitrequestID", carentrypermitrequest.getCarentrypermitrequestId());
                        fields.put("Building", empBuild.equals("المبنى الرئيسي") ? 1 : 2);
    
                        empMobileDisable = true;
                    }
                    processHandler.doLaunch(fields);
    
                    String queueName = "";
                    if (empBuild.equals(MAIN_BUILDING_VALUE)) {
                        queueName = MAIN_BUILDING_QUEUE;
                    } else if (empBuild.equals(BUSINESS_BUILDING_VALUE)) {
                        queueName = BUSINESS_BUILDING_QUEUE;
                    }
                    List<String> toList = getPublicInboxUsersEmails(queueName);
                    String mailSubject = "eeeeeeeeeeeee";
                    String mailBody = createMailBodyForNewRequest();
                    String imageName = "moamalatIcon.jpg";
                    String bannerPath = NotificationThread.class.getResource(imageName).getPath();
                    NotificationThread thread = new NotificationThread(toList, mailSubject, mailBody, configs, bannerPath);
                    thread.start();
    
                    String[] paramsArray = { carentrypermitrequest.getPlatenumber(), requestId.toString(),
                            GeneralUtils.getConfig("CAR_INQUIRE_URL") };
                    sendSMSNotificaiton(empMobile, ProcessConstant.SMS_CODE_CAR_PASS_RECEIVED, paramsArray);
    
                }
    
                else if (stepNumber == STEP_NUMBER_EMPLOYEE_ACTION) { // security manager step
                    requestContext.addCallbackParam("isValid2", true);
    
                    Integer carentrypermitrequestID = (Integer) processHandler.getStepElement()
                            .getParameterValue("carentrypermitrequestID");
    
                    if (dManaSecurityApprove == null || dManaSecurityApprove == 0) {
    
                        addErrorMessage("yyyyyyyyyy", null, true);
                        requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                        requestContext.addCallbackParam("isValid2", false);
    
                        return;
                    }
    
                    if ((permissiondate == null || permissiondate.trim().length() == 0 || permissionenumber == null
                            || permissionenumber.trim().length() == 0) && (dManaSecurityApprove == 1)) {
    
                        Boolean test = false;
                        addErrorMessage(" oooooooooooo", null, true);
                        requestContext.addCallbackParam("isValid", test);
                        requestContext.addCallbackParam("isValid2", false);
                        return;
    
                    }
    
                    carentrypermitrequest.setSecuritymanagernotes(securityManagerNotes);
    
                    securityManager = new IoDepartmentsHome()
                            .findById(Integer.parseInt((configs.getProperty(ProcessConstant.DEP_Security_DEP))))
                            .getIoEmployeesByManagerid();
    
                    carentrypermitrequest.setSecuritymanager(securityManager);
    
                    IoEmployees actionEmployee = ioemployeeHome.findByUserId(getUserName());
                    carentrypermitrequest.setActionEmployee(actionEmployee);
    
                    if (dManaSecurityApprove.equals(1)) {
    
                        platenumber = getPlateString(plateNumerSplited);
                        carentrypermitrequest.setPlatenumber(platenumber);
                        CarType cartypeobj = cartypehome.findById(cartypevalue);
                        carentrypermitrequest.setCartypeId(cartypeobj);
                        CarCategory carcategoryobj = carcategoryehome.findById(carcategoryvalue);
                        carentrypermitrequest.setCarcategoryId(carcategoryobj);
                        CarColor carcolorobj = carcolorhome.findById(carcolorvalue);
                        carentrypermitrequest.setCarcolorId(carcolorobj);
                        carentrypermitrequest.setCarmodel(model);
    
                        carentrypermitrequest.setPermissioncase(permissioncase);
                        permissiondate = permissiondate.replace("/", "");
                        carentrypermitrequest.setPermissiondate(new Integer(permissiondate));
                        carentrypermitrequest.setPermissionenumber(new Integer(permissionenumber));
                        carentrypermitrequest.setVersionnumber(new Integer(versionnumber));
                        carentrypermitrequest.setLicenseVersion(licenseVersion);
                        carentrypermitrequest.setAccepted(1);
                        carentrypermitrequest.setAcceptDate(new Date());
                        carentrypermitrequest.setAcceptedBy(loggedInUserId);
                        carentrypermitrequest.setRequestStatus(CarEntryPermitRequestStatusEnum.ACCEPTED.getValue());
                        if (isexpireDate == true || permissioncase.equals(PERMIT_TYPE_TEMPORARY)) {
                            if (expireDate == null || expireDate.length() == 0) {
                                addErrorMessage("mmmmmmmmmmmm", null, true);
                                requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                                return;
                            }
                            String expireDatestr = expireDate.replace("/", "");
                            carentrypermitrequest.setExpiredate(new Integer(expireDatestr));
    
                            String hijriYear = expireDate.substring(0, 4);
                            String hijriMonth = expireDate.substring(5, 7);
                            String hijriDay = expireDate.substring(8);
                            String expireDateGreg = convertFromHijriToGreg(hijriYear, hijriMonth, hijriDay);
    
                            fields.put("expire", true);
                            fields.put("expireDate", expireDateGreg);
    
                        }
    
                        fields.put("decisionManaSecurityNum", 1);
                        fields.put("carentrypermitrequestID", carentrypermitrequestID);
    
                        processHandler.doComplete(fields);
                        sendSMSNotificaiton(empMobile, ProcessConstant.SMS_CODE_CAR_PASS, new String[] {});
    
                    }
                    if (dManaSecurityApprove.equals(2)) {
    
                        if (showSecurityManSec && StringUtils.isBlank(securityManagerNotes)) {
                            addErrorMessage("qqqqqqqqqq", null, true);
                            requestContext.addCallbackParam("isValid", Boolean.valueOf(false));
                            requestContext.addCallbackParam("isValid2", false);
                            return;
                        }
                        carentrypermitrequest.setRejectDate(new Date());
                        carentrypermitrequest.setRejectedBy(loggedInUserId);
                        carentrypermitrequest.setRejectReason(securityManagerNotes.trim());
                        carentrypermitrequest.setRequestStatus(CarEntryPermitRequestStatusEnum.REJECTED.getValue());
                        fields.put("refusedfrom", 1);
                        fields.put("decisionManaSecurityNum", 2);
                        fields.put("carentrypermitrequestID", carentrypermitrequestID);
                        processHandler.doComplete(fields);
                        String rejectReason = securityManagerNotes;
                        if (securityManagerNotes.length() > 20) {
                            rejectReason = securityManagerNotes.substring(0, 20) + "...";
                        }
                        String[] paramsArray = { carentrypermitrequest.getPlatenumber(), rejectReason };
                        sendSMSNotificaiton(empMobile, ProcessConstant.SMS_CODE_CAR_PASS_REJECTED, paramsArray);
                    }
    
                    if (dManaSecurityApprove.equals(3)) {
    
                        if (selectedEmp != null) {
    
                            fields.put("SecurityEmp", new String[] { selectedEmp });
                        }
                        fields.put("decisionManaSecurityNum", 3);
                        fields.put("carentrypermitrequestID", carentrypermitrequestID);
                        processHandler.doComplete(fields);
                    }
    
                    loadCredentials(
                            (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
    
                    // sometimes this throws rollbackexception
                    carentrypermitrequesthome.merge(carentrypermitrequest);
                    // carentrypermitrequesthome.attachDirty(carentrypermitrequest);
                    this.transaction.commit();
                }
    
            } catch (Exception e) {
                AppLogger.Log("######### EXCEPTION WITH CAR ENTRY REQUEST NUMBER: "
                        + carentrypermitrequest.getCarentrypermitrequestId() + " WITH USER: " + loggedInUserId
                        + ",stepNumber: " + stepNumber + ",permissionNumber: " + permissionenumber
                        + ",getTranscationStatus: " + getTranscationStatus());
                AppLogger.Log(e);
                RequestContext.getCurrentInstance().addCallbackParam("isValid", Boolean.valueOf(false));
                RequestContext.getCurrentInstance().addCallbackParam("error", true);
            }
        }
    

    我想知道是什么导致了RollbackException,因为抛出的异常不包含除上面发布的内容以外的任何细节。

    2 回复  |  直到 3 年前
        1
  •  2
  •   Luca Tampellini    6 年前

    在过去,我一直在努力解决同样的问题:我试图用一些新数据更新一个实体,并不断收到这个消息 RollBackException 没有任何痕迹。

    在对Hibernate的源代码进行了几个小时的调试之后,我发现 另一个完全不同的异常是以前从Hibernate的源代码中抛出的,并在一个空的 catch 阻挡并从任何外部视图中消失。这打破了传统 EntityManager 我用来合并数据的。

    尤其是,Hibernate试图实例化进程中所需的另一个实体,但找不到默认的公共构造函数。

    Hibernate的代码如何包含空的代码行 抓住 积木对我来说还是未知的。 我使用的版本是 4.3.5.Final .

    我猜您也遇到了同样的问题:一些异常,可能与我遇到的异常(缺少公共默认构造函数)性质不同,是从hibernate层抛出的,在那里被捕获,然后无论如何都不被管理。

    我建议你用同样的方法:

    下载Hibernate的源代码,并在其中迭代过程调用的所有方法,特别是留意空的catch块。 请注意,在我的示例中,空catch块不属于在 回滚异常 !



    这里有一个链接到我在上个月创建的帖子 讨论我的问题:

    CodeRanch - RollbackException thrown when adding ManyToOne relationship

        2
  •  0
  •   Mostafa Vatanpour    6 年前

    我认为您每次都必须初始化事务,但您在此行中声明事务为final:

    public final UserTransaction transaction = getUserTransaction();
    

        3
  •  0
  •   Atmas    3 年前

    如果您还没有尝试过这一点,那么如果打开SQL参数绑定和语句日志记录,可能会更快地指出模式/问题。然后,您可以看到是否有某些语句或值始终出现在您看到回滚之前。要设置两个log4j属性来显示此信息。如果你想试一试的话,这是一个非常详细的页面。

    https://thorben-janssen.com/hibernate-tips-how-to-log-sql-statements-and-their-parameters/