-->
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: How to refresh second level cache after direct SQL update?
PostPosted: Fri Jan 27, 2006 6:42 pm 
Beginner
Beginner

Joined: Sun Dec 28, 2003 3:29 pm
Posts: 22
Location: Massachusetts USA
Hello, I am using direct SQL to update a table that has a second level cache (EhCache) with read-write concurrency. Rows updated with direct SQL which are in the second level cache need to be refreshed in the cache in order to be in synch with the database. Is it possible to refresh the second level cache or even to clear it so Hibernate will reread the underlying database? If so, how?
Peter

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: MySQL 4.1.11-nt

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 6:50 pm 
Newbie

Joined: Wed Feb 23, 2005 1:02 pm
Posts: 13
Location: Sacramento, CA
check out: sessionFactory.evict* methods... they'll let you clear one or many objects at a time (per class).

_________________
-Joel Thompson

http://www.rhinosystemsinc.com
Specializing in Oracle, Java and J2EE Systems for Unix and Windows platforms


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 11:30 pm 
Beginner
Beginner

Joined: Sun Dec 28, 2003 3:29 pm
Posts: 22
Location: Massachusetts USA
rhinosystemsinc.com wrote:
check out: sessionFactory.evict* methods... they'll let you clear one or many objects at a time (per class).


It appears that sessionFactory.evict deals with the session not the second level cache (ehcache in this case). I did try using evict but it only evicts from the session. The now-obsolete entries in ehcache are still there and will be used to repopulate the object into the session, with obsolete data.

I need to be able to tell the second level cache (ehcache) to refresh its contents or clear its contents. Is there a way to do that?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 9:06 pm 
Newbie

Joined: Wed Feb 23, 2005 1:02 pm
Posts: 13
Location: Sacramento, CA
Check again.
According to the V3 reference doc :

"For the second-level cache, there are methods defined on SessionFactory for evicting the cached state of an instance, entire class, collection instance or entire collection role."

_________________
-Joel Thompson

http://www.rhinosystemsinc.com
Specializing in Oracle, Java and J2EE Systems for Unix and Windows platforms


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 9:14 pm 
Newbie

Joined: Wed Feb 23, 2005 1:02 pm
Posts: 13
Location: Sacramento, CA
ehcache is your first-level of cache (it is only for the current session). 2nd level cache is managed by SessionFactory and spans sessions (within a JVM, and actually supposed to work in cluster - never tried that however)... Try evicting/flush..etc. from each of the session and sessionfactory and you should be able to get the results - I'd think - if not post some sample code and I'll see if I can help with what you're doing...

_________________
-Joel Thompson

http://www.rhinosystemsinc.com
Specializing in Oracle, Java and J2EE Systems for Unix and Windows platforms


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 28, 2006 9:31 pm 
Newbie

Joined: Wed Feb 23, 2005 1:02 pm
Posts: 13
Location: Sacramento, CA
sorry, mispoke ehcache manages your 2nd level cache JVM-Level (I just checked the manual)...the rest of what I said about session & factory should work.

_________________
-Joel Thompson

http://www.rhinosystemsinc.com
Specializing in Oracle, Java and J2EE Systems for Unix and Windows platforms


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 29, 2006 2:58 am 
Beginner
Beginner

Joined: Sun Dec 28, 2003 3:29 pm
Posts: 22
Location: Massachusetts USA
rhinosystemsinc.com wrote:
sorry, mispoke ehcache manages your 2nd level cache JVM-Level (I just checked the manual)...the rest of what I said about session & factory should work.


Thanks for the suggestion and information. Session flush, evict and refresh were tried with apparently no effect on ehcache evidenced by the non-updated rows being returned despite the database having been updated. It's as if the 1st and 2nd level caches are simply independent. And I'm OK with that I just need a way for Hibernate to tell the 2nd level cache to refresh itself or clear itself or a way to directly access the 2nd level cache. For example, would the ehcache CacheManager work for this?

In the meantime I will try to put together an example of the problem.


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.