Re: help: Why is there validation w/ a delete action

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sat Jul 05 2008 - 06:43:24 EDT

  • Next message: Andrus Adamchik: "Re: out-of-container JNDI"

    I don't think delete rules are the cause here. The validation points
    to the Topic object.

    Usually this happens when the same context is used for multiple
    unrelated operations, and not committed/rolledback properly, so there
    are leftovers from the previous operation in some unpredictable state.
    This often happens when session context is reused between requests,
    but other scenarios are possible too.

    My recommendation is to log context.newObjects() /
    context.deletedObjects() / context.modifiedObjects() before commit to
    see what you have there. You may see some "surprises".

    Andrus

    On Jul 3, 2008, at 6:24 PM, Scott Anderson wrote:

    > In my experience, this generally means you've created an invalid state
    > in the object model. You might try nullifying any relationships that
    > the
    > object has before deleting it, since I can't remember if Cayenne
    > will do
    > that for you - I believe that relationships are marked ON DELETE
    > RESTRICT by default.
    >
    > -----Original Message-----
    > From: Chad Smith [mailto:chadksmith..mail.com]
    > Sent: Thursday, July 03, 2008 10:45 AM
    > To: use..ayenne.apache.org
    > Subject: help: Why is there validation w/ a delete action
    >
    > Can someone tell me why I get a "Cayenne validation" exception when
    > I'm
    > trying to delete an object? Here is the stack trace ...
    >
    > ------------------------------------------------------------
    > Caused by: org.apache.cayenne.validation.ValidationException: [v.2.0.3
    > May 6 2007] Validation has failed.
    > Validation failure for
    > com.gteam.gtools.knowledgeBase.Topic.updateDate:
    > "updateDate" is required.
    > Validation failure for com.gteam.gtools.knowledgeBase.Topic.topic:
    > "topic" is required.
    > Validation failure for com.gteam.gtools.knowledgeBase.Topic.validFlag:
    > "validFlag" is required.
    > Validation failure for
    > com.gteam.gtools.knowledgeBase.Topic.updateUserId: "updateUserId" is
    > required.
    > at
    > org
    > .apache.cayenne.access.ObjectStoreGraphDiff.validateAndCheckNoop(Obje
    > ctStoreGraphDiff.java:112)
    > at
    > org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:
    > 120
    > 9)
    > at
    > org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:
    > 113
    > 0)
    > at com.gteam.gtools.cayenne.CayenneDao.delete(CayenneDao.java:166)
    > at
    > com
    > .gteam.gtools.knowledgeBase.KnowledgeBaseDao.delete(KnowledgeBaseDao.
    > java:94)
    >
    > ------------------------------------------------------------
    >
    > ... here is the code that generates the exception ...
    >
    > ------------------------------------------------------------
    > DAO class ...
    >
    > public boolean deleteTopic(int topicId) throws
    > DataAccessException {
    > Topic topic = loadTopic(topicId);
    > this.delete(topic);
    > return true;
    > }
    >
    > DAO super class ...
    >
    > public boolean delete(Object object) throws DataAccessException {
    >
    > ((CayenneDataObject
    > )object).getDataContext().deleteObject((Persistent)ob
    > ject);
    > if (Transaction.getThreadTransaction() == null) {
    >
    > ((CayenneDataObject)object).getDataContext().commitChanges();
    > if (debug)
    > log.debug("CayenneDao >>> thread transaction not
    > present
    >
    > committing");
    > } else {
    > if (debug)
    > log.debug("CayenneDao >>> thread transaction present
    > commit deferred");
    > }
    > return true;
    > }
    > ------------------------------------------------------------
    > ... all my DAO's subclass a CayenneDao object.
    >
    > It's not at all clear to me why validation happens on a delete
    > event ???
    >
    > thanks in advance.
    >
    > Chad
    >



    This archive was generated by hypermail 2.0.0 : Sat Jul 05 2008 - 06:43:58 EDT