Re: Validation error that shouldn't be (I don't think)

From: Todd O'Bryan (toddobrya..ac.com)
Date: Mon Feb 20 2006 - 06:52:42 EST

  • Next message: Tomi NA: "Re: username/password in node xml definition"

    OK. I'm stumped...here's the whole code for the method that's causing
    the problem, along with the exception iterator that Andrus suggested
    at the bottom, and a few other print statements sprinkled throughout.
    I should emphasize that, if I include the if statement that's
    commented out, this works. (Note also that the dbQuestions are always
    null; I haven't even *started* testing the else.

            public void commitToDb(DataContext dc) {
                    System.out.println(getAuthor());
                    /*if (getAuthor().getPersistenceState() == PersistenceState.HOLLOW) {
                            setAuthor((User) dc.refetchObject(getAuthor().getObjectId()));
                    }*/
                    try {
                    if (dbQuestion == null) {
                            // create new one
                            dbQuestion = (ObQuestion) dc.createAndRegisterNewObject
    (ObQuestion.class);
                            dbQuestion.setAuthor(getAuthor());
                            dbQuestion.setType(getType());
                            dbQuestion.setIsVetted(Boolean.FALSE);
                            dbQuestion.addToData(ObQuestionDatum.createNew(dc, TEXT, getText
    (), null));
                            dbQuestion.addToData(ObQuestionDatum.createNew(dc, EXPLANATION,
    getExplanation(), null));
                            dbQuestion.addToData(ObQuestionDatum.createNew(dc, CORRECT_NUMBER,
    null, getCorrectNumber()));
                            for (int i = 0; i < getChoices().length; i++) {
                                    dbQuestion.addToData(ObQuestionDatum.createNew(dc, CHOICES,
    getChoices()[i], i));
                            }
                    } else {
                            //update the one we've got
                            dbQuestion.getValue(TEXT).setText(getText());
                            dbQuestion.getValue(EXPLANATION).setText(getExplanation());
                            dbQuestion.getValue(CORRECT_NUMBER).setNumericValue
    (getCorrectNumber());
                            List<ObQuestionDatum> dbChoices = dbQuestion.getValues(CHOICES);
                            for (ObQuestionDatum choice : dbChoices) {
                                    choice.setText(getChoices()[choice.getNumericValue()]);
                            }
                    }
                    dbQuestion.setLastModified(new Date());
                    dbQuestion.getDataContext().commitChanges();
                    } catch (ValidationException e) {
                            System.out.println(getAuthor());
                            Iterator it = e.getValidationResult().getFailures().iterator();
                            while(it.hasNext()) {
                              ValidationFailure f = (ValidationFailure) it.next();
                              Object source = f.getSource();
                              System.out.println(source);
                            }

                    }
            }

    Here are the results of the print statements, with labels:

    This is the first print, the result of getAuthor()
    {<ObjectId:User, id=221>; hollow; []}

    This is getAuthor() after setting the value in the database
    {<ObjectId:User, id=221>; new; [toUserPages=>?; organizations=>?;
    studentSections=>?; toOutMessages=>?; exchanges=>?; toAssignments=>?;
    teacherSections=>?; files=>?; toSkins=>?; groups=>?;
    studentForums=>?; obligations=>?; toInMessages=>?; toGrades=>?;
    toTardys=>?; absences=>?; teacherForums=>?; messages=>?; toAnswers=>?]}

    These are all the problems from iterating through the
    ValidationException
    {<ObjectId:User, id=221>; new; [toUserPages=>?; organizations=>?;
    studentSections=>?; toOutMessages=>?; exchanges=>?; toAssignments=>?;
    teacherSections=>?; files=>?; toSkins=>?; groups=>?;
    studentForums=>?; obligations=>?; toInMessages=>?; toGrades=>?;
    toTardys=>?; absences=>?; teacherForums=>?; messages=>?; toAnswers=>?]}
    {<ObjectId:User, id=221>; new; [toUserPages=>?; organizations=>?;
    studentSections=>?; toOutMessages=>?; exchanges=>?; toAssignments=>?;
    teacherSections=>?; files=>?; toSkins=>?; groups=>?;
    studentForums=>?; obligations=>?; toInMessages=>?; toGrades=>?;
    toTardys=>?; absences=>?; teacherForums=>?; messages=>?; toAnswers=>?]}
    {<ObjectId:User, id=221>; new; [toUserPages=>?; organizations=>?;
    studentSections=>?; toOutMessages=>?; exchanges=>?; toAssignments=>?;
    teacherSections=>?; files=>?; toSkins=>?; groups=>?;
    studentForums=>?; obligations=>?; toInMessages=>?; toGrades=>?;
    toTardys=>?; absences=>?; teacherForums=>?; messages=>?; toAnswers=>?]}
    {<ObjectId:User, id=221>; new; [toUserPages=>?; organizations=>?;
    studentSections=>?; toOutMessages=>?; exchanges=>?; toAssignments=>?;
    teacherSections=>?; files=>?; toSkins=>?; groups=>?;
    studentForums=>?; obligations=>?; toInMessages=>?; toGrades=>?;
    toTardys=>?; absences=>?; teacherForums=>?; messages=>?; toAnswers=>?]}
    {<ObjectId:User, id=221>; new; [toUserPages=>?; organizations=>?;
    studentSections=>?; toOutMessages=>?; exchanges=>?; toAssignments=>?;
    teacherSections=>?; files=>?; toSkins=>?; groups=>?;
    studentForums=>?; obligations=>?; toInMessages=>?; toGrades=>?;
    toTardys=>?; absences=>?; teacherForums=>?; messages=>?; toAnswers=>?]}
    {<ObjectId:User, id=221>; new; [toUserPages=>?; organizations=>?;
    studentSections=>?; toOutMessages=>?; exchanges=>?; toAssignments=>?;
    teacherSections=>?; files=>?; toSkins=>?; groups=>?;
    studentForums=>?; obligations=>?; toInMessages=>?; toGrades=>?;
    toTardys=>?; absences=>?; teacherForums=>?; messages=>?; toAnswers=>?]}

    As I look at the code, could the problem be that the author and the
    dbQuestion are in different DataContexts? If so, I thought I'd get an
    error about not being able to set getAuthor() as a relationship, but
    that would explain why refetching into this DataContext works. (As I
    said before, the DataContext is stored as a Session variable per
    user, so I can't figure out how I'm getting multiple DataContexts for
    one user.)

    What am I doing wrong?????

    TIA,
    Todd



    This archive was generated by hypermail 2.0.0 : Mon Feb 20 2006 - 06:52:50 EST