cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Lewis <br...@maine.rr.com>
Subject can't modify relationships in validateForUpdate()?
Date Mon, 27 Nov 2006 17:31:13 GMT
We have some code in a DataObject's validateForUpdate() method that
modifies the object's relationships.  It had been working fine for over
a year, although it's not exercised very often because it's only called
when an employee leaves.  Today it threw a ConcurrentModification, so
I'm guessing there was some related change in Cayenne in the last few
months.  It reminds me of the guideline we used to follow with our old
WebObjects apps, shouldn't modify an object in -validateForSave... maybe
now that's a good rule in Cayenne too?


    public void validateForUpdate(ValidationResult validationResult)
    {
        DataContext dc = getDataContext();
        DataRow oldData =
dc.getObjectStore().getSnapshot(this.getObjectId());
        Boolean oldIsActive = (Boolean) oldData.get("ISACTIVE");
        Boolean newIsActive = getIsActive();
        // If the employee is being made inactive...
        if (oldIsActive.equals(Boolean.TRUE) &&
newIsActive.equals(Boolean.FALSE)) {
            // Clear the employee's roles.
            // Use a ListIterator to allow concurrent modification.
            for (ListIterator it = getRoles().listIterator();
it.hasNext(); ) {
                Role role = (Role) it.next();
                it.remove();
                removeFromRoles(role);
            }
        }
    }


The exception:

org.objectstyle.cayenne.access.ObjectStoreGraphDiff.validateAndCheckNoop(ObjectStoreGraphDiff.java:109)
org.objectstyle.cayenne.access.DataContext.flushToParent(DataContext.java:1244)
org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:1165)

This is with Cayenne 1.2.1.


Mime
View raw message