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

From: Todd O'Bryan (toddobrya..ac.com)
Date: Sun Feb 19 2006 - 21:10:15 EST

  • Next message: Todd O'Bryan: "Re: Validation error that shouldn't be (I don't think)"

    On Feb 19, 2006, at 7:27 PM, Andrus Adamchik wrote:

    >
    > On Feb 19, 2006, at 9:48 AM, Todd O'Bryan wrote:
    >
    >>
    >> I have another object which has a User as its author. I set this
    >> by doing
    >>
    >> object.setAuthor(getUser());
    >>
    >> When I try to commit, I get lots of errors about the user saying
    >> that mandatory fields haven't been set. So I printed the User I
    >> was trying to set as the author, and it turns out that it's
    >>
    >> {[]<oid: <ObjectId:User, id=221>; state: hollow>}
    >
    > I suspect you are printing the wrong object. You need to catch the
    > ValidationException and iterate through the failures to see what
    > objects caused them:
    >
    > ValidationException e;
    > Iterator it = e.getValidationResult().getFailures().iterator();
    > while(it.hasNext()) {
    > ValidationFailure f = (ValidationFailure) it.next();
    > Object source = f.getSource();
    > ...
    > }

    Here's the code that causes the error.

                    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));
                            }

    The only User type in there is the author, which is stored as a field
    for the object this method is in. If I add this:

                    if (getAuthor().getPersistenceState() == PersistenceState.HOLLOW) {
                            setAuthor((User) dc.refetchObject(author.getObjectId()));
                    }

    to manually refetch the object, the exception goes away. Something
    fishy is going on.

    Todd



    This archive was generated by hypermail 2.0.0 : Sun Feb 19 2006 - 21:10:22 EST