-->
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.  [ 4 posts ] 
Author Message
 Post subject: Strange behaviour with 2nd level cache
PostPosted: Thu Sep 29, 2005 9:30 pm 
Beginner
Beginner

Joined: Mon Sep 26, 2005 5:57 pm
Posts: 39
I have a piece of code such as below:
Code:
public bool IsTaskAllowed(Task task)
{
   bool retVal = false;
   foreach(Task t in this.Tasks)
   {
      if (t == task)
      {
         retVal = true;
      }
   }
   return retVal;
}


In the above code, the Task object being passed in came from the 2nd level cache (I verified this by SQL profiling). However, the above code returns false, even though I know for sure, that the passed in task object is a member of this.Tasks. It appears to me, that after enabling the 2nd level cache, the objects retrieved from the cache are treated like "2nd class", which means that code written like above will fail.

Is the above behaviour expected?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 3:55 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Second-level cache gives back copies of objects, it does not do object uniquing, so that might be the problem you're hitting here.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 3:37 pm 
Any suggestions as to how can I deal with this problem?

Basically, the problem I am trying to solve is:

I have some objects that I query by a property (not Id), and I want these to be cached, as these may be used a lot on every single page load.

So, even if the objects are stored in the 2nd level cache, there is no way to Get them out of the cache.

I tried manually putting these objects into cache, but I am getting a behaviour where the cached objects do not appear to be unique. Maybe because they are disconnected from the original session??

Any suggestions?


Top
  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 4:36 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The easiest way would be to implement Task.Equals and use that instead of == in the method you posted. Then you can enable query caching for the query you use to load the objects by a property, this should also help a bit.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.