-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Cached Objects not being refreshed on re-query
PostPosted: Fri Oct 20, 2006 1:06 pm 
Newbie

Joined: Tue Mar 21, 2006 3:11 pm
Posts: 10
In my c# winform application I have a form with a list of tasks that users can work on. When a user begins working one, the row is updated to reflect this. The application tries to refresh the list of tasks once a minute, but updates aren't being reflected in the objects returned from queries in other sessions. So, other users are not seing the fact that a task has been updated by another user (and session).

I have tried using SetCacheable(false) and SetForceCacheRefresh(true) but I still get old copies of the objects.

I get this using both 1.0.2 and 1.2b.

I tried manully evicting the object returned from the prior query and this works for the main object, but dependent objects returned in collections are not. So, I imagine I would need to evict these as well. Doing it this way seems kind of messy though. I know a Session.Clear() could be done, but this seems extreme.

Below is the snippet of code I am executing. So, what am I doing wrong? Is there a better approach that I just missed?

Code:
IQuery q
  = session.CreateQuery(
        "select ca from CreditApplication ca inner join ca.CreditApplicationStateList currstate "
     + " where currstate.AppState = :appstate "
     + " and currstate.DateTimeStateEntered <= :now  and currstate.DateTimeCompleted >= :now "
     + (merchId > 0 ? " and ca.Merchid = :merchid " : "")
     );
               
   q.SetDateTime("now", DateTime.Now);
   q.SetString("appstate", (state != null && state.Length > 0 ? state : "PROCESSING_TERMINATED"));

   if (merchId > 0)
       q.SetInt32("merchid", merchId);

    q.SetCacheable(false)
      .SetForceCacheRefresh(true)
                 ;

   IList apps = q.List();



I also tried switching query cache off but this didn't have an effect. I also switched to the prevalence cache and set the expiration to 1 second. This didn't seem to help either.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 3:53 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Are you Flush() the sessing changes?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 4:20 pm 
Newbie

Joined: Tue Mar 21, 2006 3:11 pm
Posts: 10
I am flushing and committing the changes in Session A. I went to db and verified the changes where there and they are. So, if the objects had already been loaded into Session B, then the updates are not showing up, unless I force a refresh of each object.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 7:46 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Well, that is to be expected, isn't it?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 11:26 pm 
Newbie

Joined: Tue Mar 21, 2006 3:11 pm
Posts: 10
I understand the updates would not show up automatically and that I would have to initiate retrieval of changes. But I guess I expected that if I did a query, that would get the changes. If I understand what you are saying, then I can't use a query to refresh object state from the database and I have to evict all objects to be refreshed (and dependent objects), call session.Refresh() on the objects or call session.Clear() (sort of the nuclear approach). Is this what you are saying?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 21, 2006 3:05 am 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Yes, it won't change the entity under you, because this may cause a lot of very hard to find issues.
What you seem to want is to get a new _copy_ of the data whenever you pull it out of the query.
If that is the case, you need to Evict() those entities.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 6:19 am 
Newbie

Joined: Wed Oct 25, 2006 5:18 am
Posts: 2
Ayende Rahien wrote:
Yes, it won't change the entity under you, because this may cause a lot of very hard to find issues.
What you seem to want is to get a new _copy_ of the data whenever you pull it out of the query.
If that is the case, you need to Evict() those entities.


Evict is a great thing for multi-user environemts. But if we have one object changed in Query collection containing, say, 100000 items, in session A (PC#1) why we should evict all of these items in session B (PC#2) from cache to make sure we show the latest changes on screen? Is that possible to supply version control here so all changed entities (with DataRowEntity.Timestamp>CachedEntity.Timestamp) will go to hydratedObjects and re-loaded from the IList DoQuery? Sorry if missed something


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.