查看条件不返回行

View Criteria not returning row

我是 ADF BC 的新手,我正在尝试在数据库中保存一条记录。 如果记录已经存在,我将更新字段,如果不存在,我将创建一个新行。

我在其他方法中使用了相同的视图条件并且它起作用了,但在这个方法中不起作用。这是我的代码:

public String saveRecord() {
boolean isNewRow = false;
String merchId = generateIds(); //returns the correct Id, I've checked

DCIteratorBinding dc = (DCIteratorBinding)evaluteEL("#{bindings.GaeInitialSetup1Iterator}");
ViewObject vo = dc.getViewObject();

ViewCriteriaManager vcm = vo.getViewCriteriaManager();
vo.setNamedWhereClauseParam("merchId", merchId);
vcm.applyViewCriteria(vo.getViewCriteriaManager().getViewCriteria("GaeInitialSetupVOCriteria"));
vo.executeQuery(); 

Row rowSelected = vo.next(); //it's always null even if the record exists
if (rowSelected == null) { // null == null - leads to error when trying to insert the same Id twice
    isNewRow = true;
    rowSelected = vo.createRow();
    rowSelected.setAttribute("MerchId", merchId);
    rowSelected.setAttribute("MerchLevel", merchLevelCalc(merchId));
    rowSelected.setAttribute("ParentId", parentIdCalc(merchId));
} 


    rowSelected.setAttribute("IpssDefault", validateIPSSDefault());
    rowSelected.setAttribute("IpssBase", validateIPSSBase());
    rowSelected.setAttribute("LimMinMdqPct", validateLIM_MIN_MDQ_PCT());
    rowSelected.setAttribute("LimMinMdqPctNewSku", validateLIM_MIN_MDQ_PCT_NEW_SKU());
    rowSelected.setAttribute("DifMdqPctMin", validateDIF_MDQ_PCT_MIN());
    rowSelected.setAttribute("VarMinMdqChg", validateVAR_MIN_MDQ_CHG());
    rowSelected.setAttribute("LimMinRotDays", validateLIM_MIN_ROT_DAYS());
    rowSelected.setAttribute("LimMaxRotDays", validateLIM_MAX_ROT_DAYS());
    rowSelected.setAttribute("DaysNewSku", validateDAYS_NEW_SKU());
    rowSelected.setAttribute("IncrS1", validateINCR_S1());
    rowSelected.setAttribute("IncrS2", validateINCR_S2());
    rowSelected.setAttribute("IncrS3", validateINCR_S3());
    rowSelected.setAttribute("IncrS4", validateINCR_S4());
    rowSelected.setAttribute("ReplSuspComb", validateREPL_SUSP_COMB());
    rowSelected.setAttribute("VarPctMinStkRot", validateVAR_PCT_MIN_STK_ROT());
    rowSelected.setAttribute("AbcgA", validateABCG_A());
    rowSelected.setAttribute("AbcgB", validateABCG_B());
    rowSelected.setAttribute("AbcgC", validateABCG_C());
    rowSelected.setAttribute("AbcgD", validateABCG_D());
    rowSelected.setAttribute("AbcgE", validateABCG_E());
    rowSelected.setAttribute("AbcgF", validateABCG_F());
    rowSelected.setAttribute("AbcgG", validateABCG_G());

    if (isNewRow) {
        vo.insertRow(rowSelected);
    }


DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = (OperationBinding)bindings.getOperationBinding("Execute");
operationBinding.execute();

OperationBinding operationBinding2 = (OperationBinding)bindings.getOperationBinding("Commit");
operationBinding2.execute();

return null;

}

我错过了什么?

您的代码看起来完全正确,您可以尝试进行以下提到的更改吗?

vo.executeQuery();
if (vo.hasNext()) { 
  Row rowSelected = vo.next(); 
//write rest of your logic here

    }

这不会有 null == null 检查,是最佳实践。

我已经解决了这个问题。

我删除了以下行:Row rowSelected = vo.next();

我还添加了:Row rowSelected = vo.first();