Thanks Andrus.
What is the best approach for a web app then?
Currently I have a filter that does this on the front end of the request ...
------------------------------------------------
HttpSession session = ((HttpServletRequest)servletRequest).getSession(true);
DataContext dataContext = ServletUtil.getSessionContext(session);
DataContext.bindThreadDataContext(dataContext);
------------------------------------------------
.. and does this one the backend of the request ...
------------------------------------------------
DataContext dataContext = DataContext.getThreadDataContext();
if (dataContext.hasChanges()) {
try {
dataContext.rollbackChanges();
} catch (Exception e) {
log.error(e);
}
}
DataContext.bindThreadDataContext(null);
------------------------------------------------
.... the problem is it seems like my commit validation errors are
retained across requests b/c a subsequent attempt at trying to store a
new topic object has the same validation errors repeated in the
validation stack. How do you remove validation errors from the session?
thanks in advance.
Chad
Andrus Adamchik wrote:
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:[EMAIL PROTECTED]
Sent: Thursday, July 03, 2008 10:45 AM
To: [email protected]
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