I have a web app that uses Cayenne 2.0.4 w/ Spring and it uses a servlet filter to manage the data context ...
Request init code
--------------------------------
HttpSession session = ((HttpServletRequest)servletRequest).getSession(true);
DataContext dataContext = ServletUtil.getSessionContext(session);
DataContext.bindThreadDataContext(dataContext);
Request destroy code
--------------------------------
DataContext dataContext = DataContext.getThreadDataContext();
if (dataContext.hasChanges()) {
dataContext.rollbackChanges();
}
DataContext.bindThreadDataContext(null);
... I also have a parent table and child table in which the child table has a circular reference to itself
parent table: Forum
forum.forum_id
child table: forum_thread
forum_thread.forum_id
forum_thread.thread_id
forum_thread.parent_thread_id (the circular reference)
... here is the cayenne mapping xml for the relationships ...
<db-relationship name="forumToThread" source="forum" target="forum_thread" toMany="true">
<db-attribute-pair source="forum_id" target="forum_id"/>
</db-relationship>
<db-relationship name="subThreadToThread" source="forum_thread" target="forum_thread" toMany="false">
<db-attribute-pair source="parent_thread_id" target="thread_id"/>
</db-relationship>
<db-relationship name="threadToForum" source="forum_thread" target="forum" toMany="false">
<db-attribute-pair source="forum_id" target="forum_id"/>
</db-relationship>
<db-relationship name="threadToSubThread" source="forum_thread" target="forum_thread" toMany="true">
<db-attribute-pair source="thread_id" target="parent_thread_id"/>
</db-relationship>
<obj-relationship name="forumToThread" source="Forum" target="Thread" deleteRule="Cascade" db-relationship-path="forumToThread"/>
<obj-relationship name="subThreadToThread" source="Thread" target="Thread" db-relationship-path="subThreadToThread"/>
<obj-relationship name="threadToForum" source="Thread" target="Forum" db-relationship-path="threadToForum"/>
<obj-relationship name="threadToSubThread" source="Thread" target="Thread" deleteRule="Cascade" db-relationship-path="threadToSubThread"/>
... here is the code I'm using to delete a thread ...
public boolean deleteThread(int threadId) throws DataAccessException {
// NOTE: transactions are auto commit unless otherwise specified!
Thread thread = loadThread(threadId);
// remove any parent association
if (thread.getSubThreadToThread() != null) {
Thread parentThread = thread.getSubThreadToThread();
parentThread.removeFromThreadToSubThread(thread);
}
// remove forum association
Forum forum = thread.getThreadToForum();
forum.removeFromForumToThread(thread);
super.delete(thread);
return true;
}
... so here is the problem: I setup the following data
Forum record which has 3 top level thread records. Lets say thread 2 has several children and several grand children. When I delete one of thread 2's children it does the database deletes perfectly (cascade deletes of the correct grandchildren), however, the gui continues to show the grand children but the child record (that was deleted) is gone. Here is the SQL and the data context looks clean before and after processing ....
CayenneDao >>> --------------- Cayenne Context: 2009-01-07 06:49:40 ----------------
- hasChanges = false | isTransactionEventsEnabled = false | isUsingSharedSnapshotCache = true | isValidatingObjectsOnCommit = true
2009-01-07 06:49:40,953 INFO (QueryLogger.java:423) - --- will run 1 query.
2009-01-07 06:49:40,953 INFO (QueryLogger.java:377) - --- transaction started.
2009-01-07 06:49:40,953 INFO (QueryLogger.java:300) - DELETE FROM gtools.forum_thread WHERE thread_id = ?
2009-01-07 06:49:40,953 INFO (QueryLogger.java:322) - [bind: 228]
2009-01-07 06:49:40,968 INFO (QueryLogger.java:368) - === updated 1 row.
2009-01-07 06:49:40,968 INFO (QueryLogger.java:322) - [bind: 227]
2009-01-07 06:49:40,968 INFO (QueryLogger.java:368) - === updated 1 row.
2009-01-07 06:49:40,968 INFO (QueryLogger.java:322) - [bind: 226]
2009-01-07 06:49:40,968 INFO (QueryLogger.java:368) - === updated 1 row.
2009-01-07 06:49:41,015 INFO (QueryLogger.java:384) - +++ transaction committed.
CayenneDao >>> --------------- Cayenne Context: 2009-01-07 06:49:41 ----------------
- hasChanges = false | isTransactionEventsEnabled = false | isUsingSharedSnapshotCache = true | isValidatingObjectsOnCommit = true
... no matter where I go w/in the application the data (grand children) seems to stick in the cache but if I log off and back on they are now gone (no longer in the object cache). What am I doing wrong here? I know that is a lot to wade through but I would greatly appreciate any help on diagnosing the problem.
Thanks in advance.
Chad
This archive was generated by hypermail 2.0.0 : Wed Jan 07 2009 - 09:05:27 EST