You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Bryan Lewis <br...@maine.rr.com> on 2006/11/27 18:31:13 UTC

can't modify relationships in validateForUpdate()?

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.


Re: can't modify relationships in validateForUpdate()?

Posted by Andrus Adamchik <an...@objectstyle.org>.
Yeah, the current build produces jars similar to the old cayenne- 
nodeps.jar, so you'll have to include dependencies manually (which  
may not be a bad thing).

Alternatively (if you are looking for the bug fixes, but can wait  
with the new features), you can build the 2.0 branch which is stable,  
contains Apache package names, and still uses Ant:

https://svn.apache.org/repos/asf/incubator/cayenne/main/branches/ 
STABLE-2.0/cayenne/

Andrus



On Nov 28, 2006, at 11:26 PM, Kevin Menard wrote:
>> -----Original Message-----
>> From: Bryan Lewis [mailto:bryan@maine.rr.com]
>> Sent: Tuesday, November 28, 2006 2:01 PM
>> To: cayenne-user@incubator.apache.org
>> Subject: Re: can't modify relationships in validateForUpdate()?
>>
>> I got close, I think.  I installed maven and checked out the source
> from
>> svn, and got it to almost build.  (After commenting out the
>> "cayenne-osx" line of assembly/pom.xml.  Sensible?)  After 28 minutes
> of
>> churning :-)  it produced a few jars like
>> cayenne-jdk1.4-3.0-incubating-SNAPSHOT.jar, but none of them look  
>> like
>> the good old cayenne.jar; they don't include externals such as log4j
> for
>> example.  I'm probably missing some step.
>
> Hmm . . . the cayenne-osx stuff has been disabled for about a week  
> now,
> so you shouldn't have had to do anything manually there.  It also
> shouldn't have taken 28 min.  Granted, that will depend on your  
> machine,
> but a fresh compile takes about 8.5 min. for me.  Follow-up compiles
> take about 3 min.
>
> The build process, unfortunately, hasn't been updated yet to build
> packed JARs.  So, the easiest way to use Cayenne 3.0 for the time  
> being
> is to "mvn install" Cayenne and then add a dependency to your POM,
> providing your project uses Maven 2.  If not, you'll need to manually
> provide the dependencies for the time being.
>
> -- 
> Kevin
>


RE: can't modify relationships in validateForUpdate()?

Posted by Kevin Menard <km...@servprise.com>.
> -----Original Message-----
> From: Bryan Lewis [mailto:bryan@maine.rr.com]
> Sent: Tuesday, November 28, 2006 2:01 PM
> To: cayenne-user@incubator.apache.org
> Subject: Re: can't modify relationships in validateForUpdate()?
> 
> I got close, I think.  I installed maven and checked out the source
from
> svn, and got it to almost build.  (After commenting out the
> "cayenne-osx" line of assembly/pom.xml.  Sensible?)  After 28 minutes
of
> churning :-)  it produced a few jars like
> cayenne-jdk1.4-3.0-incubating-SNAPSHOT.jar, but none of them look like
> the good old cayenne.jar; they don't include externals such as log4j
for
> example.  I'm probably missing some step.

Hmm . . . the cayenne-osx stuff has been disabled for about a week now,
so you shouldn't have had to do anything manually there.  It also
shouldn't have taken 28 min.  Granted, that will depend on your machine,
but a fresh compile takes about 8.5 min. for me.  Follow-up compiles
take about 3 min.

The build process, unfortunately, hasn't been updated yet to build
packed JARs.  So, the easiest way to use Cayenne 3.0 for the time being
is to "mvn install" Cayenne and then add a dependency to your POM,
providing your project uses Maven 2.  If not, you'll need to manually
provide the dependencies for the time being.

-- 
Kevin

Re: can't modify relationships in validateForUpdate()?

Posted by Bryan Lewis <br...@maine.rr.com>.
That's great.   Except... does anyone have tips for building the new
cayenne?   The new "Compiling Cayenne" wiki page is unfinished.  I had
no trouble with the old ant build.

I got close, I think.  I installed maven and checked out the source from
svn, and got it to almost build.  (After commenting out the
"cayenne-osx" line of assembly/pom.xml.  Sensible?)  After 28 minutes of
churning :-)  it produced a few jars like
cayenne-jdk1.4-3.0-incubating-SNAPSHOT.jar, but none of them look like
the good old cayenne.jar; they don't include externals such as log4j for
example.  I'm probably missing some step.

I tried the old ant way.  The wiki suggests that it will still work from
the cayenne-ant directory, but I get an immediate error:

  prepare-deps:
      [unjar] Expanding:
C:\cayenne-svn\cayenne\pre-maven\cayenne-java\lib\velocity-dep-1.3.jar into
        C:\cayenne-svn\cayenne\pre-maven\cayenne-ant\build\cayenne-1_4\deps




Andrus Adamchik wrote:
> I just checked in the fix. Also I described in the docs how validation
> should behave when user methods have side effects:
>
> http://cwiki.apache.org/CAYDOC/dataobject-validation.html
>
> Andrus
>
> On Nov 27, 2006, at 8:23 PM, Bryan Lewis wrote:
>
>> Thanks!  I entered an issue CAY-712.
>>
>>
>> Andrus Adamchik wrote:
>>> Actually IIRC we did allow to do arbitrary modifications to objects
>>> within "validate*" at some point. And checking the code, I see where
>>> you getting this exception now.
>>>
>>> Could you please submit a bug report? It should be fairly easy to fix
>>> it (although it will add a bit of overhead on commit, as we will have
>>> to copy dirty objects in a separate collection). Also this time around
>>> we'll try to add a unit test, so that it doesn't get lost again :-)
>>>
>>> Andrus
>>>
>>>
>>> On Nov 27, 2006, at 12:31 PM, Bryan Lewis wrote:
>>>> 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.
>>>>
>>>>
>>>
>>
>>
>


Re: can't modify relationships in validateForUpdate()?

Posted by Andrus Adamchik <an...@objectstyle.org>.
I just checked in the fix. Also I described in the docs how  
validation should behave when user methods have side effects:

http://cwiki.apache.org/CAYDOC/dataobject-validation.html

Andrus

On Nov 27, 2006, at 8:23 PM, Bryan Lewis wrote:

> Thanks!  I entered an issue CAY-712.
>
>
> Andrus Adamchik wrote:
>> Actually IIRC we did allow to do arbitrary modifications to objects
>> within "validate*" at some point. And checking the code, I see where
>> you getting this exception now.
>>
>> Could you please submit a bug report? It should be fairly easy to fix
>> it (although it will add a bit of overhead on commit, as we will have
>> to copy dirty objects in a separate collection). Also this time  
>> around
>> we'll try to add a unit test, so that it doesn't get lost again :-)
>>
>> Andrus
>>
>>
>> On Nov 27, 2006, at 12:31 PM, Bryan Lewis wrote:
>>> 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.validateAndCheck 
>>> Noop(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.
>>>
>>>
>>
>
>


Re: can't modify relationships in validateForUpdate()?

Posted by Bryan Lewis <br...@maine.rr.com>.
Thanks!  I entered an issue CAY-712.


Andrus Adamchik wrote:
> Actually IIRC we did allow to do arbitrary modifications to objects
> within "validate*" at some point. And checking the code, I see where
> you getting this exception now.
>
> Could you please submit a bug report? It should be fairly easy to fix
> it (although it will add a bit of overhead on commit, as we will have
> to copy dirty objects in a separate collection). Also this time around
> we'll try to add a unit test, so that it doesn't get lost again :-)
>
> Andrus
>
>
> On Nov 27, 2006, at 12:31 PM, Bryan Lewis wrote:
>> 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.
>>
>>
>


Re: can't modify relationships in validateForUpdate()?

Posted by Andrus Adamchik <an...@objectstyle.org>.
Actually IIRC we did allow to do arbitrary modifications to objects  
within "validate*" at some point. And checking the code, I see where  
you getting this exception now.

Could you please submit a bug report? It should be fairly easy to fix  
it (although it will add a bit of overhead on commit, as we will have  
to copy dirty objects in a separate collection). Also this time  
around we'll try to add a unit test, so that it doesn't get lost  
again :-)

Andrus


On Nov 27, 2006, at 12:31 PM, Bryan Lewis wrote:
> 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.validateAndCheckNo 
> op(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.
>
>


Re: can't modify relationships in validateForUpdate()?

Posted by Andrus Adamchik <an...@objectstyle.org>.
I should plug my usual "check out 3.0 lifecycle callbacks" mantra :-)

http://cwiki.apache.org/CAYDOC/lifecycle-callbacks.html

of course to get this functionality, you'd need to build Cayenne from  
SVN. Hopefully we'll restore the nightly builds someday. And even  
better - graduate from Apache Incubator and start posting official  
milestone releases of 3.0 :-)

Andrus


On Nov 27, 2006, at 2:11 PM, Matt Kerr wrote:

> trying to recall ..   so, i would double check this, but --
>
>> Perhaps this is because of my WO/EOF background, but I had always
>> assumed that modifying anything in the validate* methods would be a
>> Bad Thing and never tried doing it.
>
> is this because WO/EOF specifically guides you *not* to put any  
> side-effect code into the validate* methods.
>
> but i want to say this was ok .. since there were other delegate  
> methods to tidy up before validateFor* was invoked ..
>
> (now - if i could just remember which one .. hmm.  is that right?)
>
>
>
>> I can't say I ever read it in regards to Cayenne, but it feels  
>> like the right thing to me.
>> Not sure why it changed in behavior, though.
>
>
> in cayenne -- there is no equivalent delegate .. and i believe the  
> right/best way to handle this situation is to implement the side- 
> effects in validateFor*().
>
>
> -mk
>
>


Re: can't modify relationships in validateForUpdate()?

Posted by Matt Kerr <ma...@centralparksoftware.com>.
trying to recall ..   so, i would double check this, but --

> Perhaps this is because of my WO/EOF background, but I had always
> assumed that modifying anything in the validate* methods would be a
> Bad Thing and never tried doing it.

is this because WO/EOF specifically guides you *not* to put any side- 
effect code into the validate* methods.

but i want to say this was ok .. since there were other delegate  
methods to tidy up before validateFor* was invoked ..

(now - if i could just remember which one .. hmm.  is that right?)



> I can't say I ever read it in regards to Cayenne, but it feels like  
> the right thing to me.
> Not sure why it changed in behavior, though.


in cayenne -- there is no equivalent delegate .. and i believe the  
right/best way to handle this situation is to implement the side- 
effects in validateFor*().


-mk


Re: can't modify relationships in validateForUpdate()?

Posted by Michael Gentry <bl...@gmail.com>.
Perhaps this is because of my WO/EOF background, but I had always
assumed that modifying anything in the validate* methods would be a
Bad Thing and never tried doing it.  I can't say I ever read it in
regards to Cayenne, but it feels like the right thing to me.  Not sure
why it changed in behavior, though.

/dev/mrg


On 11/27/06, Bryan Lewis <br...@maine.rr.com> wrote:
> 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.
>
>