Hi,
While calling validateFor* explicitly in the code is possible, it is
really redundant. DataContext will do it for you... So just catch
org.objectstyle.cayenne.validation.ValidationException that contains
validation result - this wil list Cayenne validation failures. Now if you
want to include this plus DB failures, then catch the superclass -
CayenneRuntimeException.
> Also, there is something wrong with the way I call
> validateForDelete() above. Sometimes, although the
> validation result is empty, I still encountered
> cayenneruntime exception when performing
> commitChanges() (usually because of the foreign key
> constraints).
DataOject default validation routine does not check the database, so the
case you mention will not be detected (see, Cayenne doesn't attempt to
second guess the DB - this would be wasteful). All default validation does
is some basic checks of the object properties. One of its more important
functions though is the ability to add custom validation by implementing
one of the "validateFor*". This is good for things that DB will not catch
(e.g. checkig CC number using some checksum algorithm, or validating an
email address).
Andrus
> Hello,
>
> I have a question about the "validateForInsert,
> validateForUpdate, validateForDelete" methods.
>
> I'm not sure when is the right time to call them.
> What I did is I just call them prior to calling
> datacontext's commitChanges(). If the validation
> result is
> empty, then proceed with commitChanges(). Am I right?
>
> For validateForUpdate(), this is what I did:
> 1. Obtain the record from database
> 2. Update necessary properties
> 3. Call validateForUpdate()
> 4. if validation result is empty, then proceed with
> data context's commitChanges().
>
> For validateForDelete():
> 1. Obtain the record from database
> 2. Call validateForDelete()
> 3. If validation result is empty, call data context's
> deleteObject, then commitChanges().
>
> Is this correct? Is it worth to perform these
> validation, or is it necessary just to leave it to
> DataContext's commitChanges(), and catch the
> CayenneRuntimeException if anything goes wrong?
>
> Also, there is something wrong with the way I call
> validateForDelete() above. Sometimes, although the
> validation result is empty, I still encountered
> cayenneruntime exception when performing
> commitChanges() (usually because of the foreign key
> constraints). In this case, what is
> validateForDelete() for??? or.. do i have to check it
> manually, since the API says that validateForDelete()
> does nothing?
>
>
> Thanks a lot for the help, and apology for the basic
> question..
>
>
> Best regards,
>
>
>
> =====
> Alex Wibowo
> ~ Second is a failure ~
> ==============================================
>
This archive was generated by hypermail 2.0.0 : Thu Dec 23 2004 - 12:53:21 EST