cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Armstrong" <siber...@gmail.com>
Subject Re: A little help w/ session state please
Date Wed, 07 Jan 2009 15:52:17 GMT
Check with Andrus on the Cayenne list. They are usually pretty good
about helping find the answer (rather then just saying 'Use 3.0!')

Good luck, glad to see others are cayenning with Wicket!

J

On Wed, Jan 7, 2009 at 7:48 AM, Chad Smith <chadksmith1@gmail.com> wrote:
> John,
>  I don't think you are missing the point and that looked promising.  But it looks like
RefreshQuery is a 3.0 bean and not available in 2.0.4.
>
> -Chad
>
> ----- Original Message -----
> From: "John Armstrong" <siberian@gmail.com>
> To: user@cayenne.apache.org
> Sent: Wednesday, January 7, 2009 8:33:08 AM GMT -07:00 US/Canada Mountain
> Subject: Re: A little help w/ session state please
>
> This I think may be more of a cayenne problem. You have to reload the
> object to destroy the cayenne cache using something like RefreshQuery.
>
> Thats what I have to do in many cases. Like this:
>
> context.deleteObject(theFeed);
> context.commitChanges();
> context.commitChangesToParent();
> context.performQuery(new RefreshQuery(theFeed));
>
> I may be missing the point entirely, sorry :)
> John-
>
> On Wed, Jan 7, 2009 at 6:04 AM, Chad Smith <chadksmith1@gmail.com> wrote:
>> 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
>>
>

Mime
View raw message