cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Anderson" <sander...@airvana.com>
Subject RE: help: Why is there validation w/ a delete action
Date Thu, 03 Jul 2008 15:24:05 GMT
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:chadksmith1@gmail.com] 
Sent: Thursday, July 03, 2008 10:45 AM
To: user@cayenne.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

Mime
View raw message