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

From: Todd O'Bryan (toddobrya..ac.com)
Date: Tue Feb 21 2006 - 18:56:21 EST

  • Next message: i.venut..aribel.it: "Re: Multiple deploys in different enviroments [was Re: username/password in node xml definition]"

    T3, still. And, yes, the Visit is Serializable. (I just checked to be
    sure.)

    Todd

    On Feb 21, 2006, at 11:15 AM, Gentry, Michael (Contractor) wrote:

    > Todd, are you using T3 or T4? Your session is serializable, right?
    >
    > Thanks,
    >
    > /dev/mrg
    >
    >
    > -----Original Message-----
    > From: Todd O'Bryan [mailto:toddobrya..ac.com]
    > Sent: Monday, February 20, 2006 6:53 AM
    > To: cayenne-use..bjectstyle.org
    > Subject: Re: Validation error that shouldn't be (I don't think)
    >
    >
    > 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 : Tue Feb 21 2006 - 18:56:33 EST