-->
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.  [ 6 posts ] 
Author Message
 Post subject: Disable Hibernate Session Cache (?)
PostPosted: Wed Apr 23, 2008 5:19 pm 
Newbie

Joined: Wed Apr 23, 2008 4:07 pm
Posts: 1
Hibernate version: Hibernate 3.2.4.sp1

I am using Hibernate as part of the Seam framework. My problem is when a field is updated by an external application the change is not reflected in the web interface.

For example, I display a data table backed by a query:

Code:
entityManager.createQuery("select c from Channel c").getResultList();


Then after changing a Channel field using an external application and refreshing the page, I see the same stale result from the first query.

However, if I do:

Code:
entityManager.clear();
entityManager.createQuery("select c from Channel c").getResultList();


The fields are refreshed from the database.

I believe Hibernate is pulling the results from its session cache, so I've tried to turn off the session cache by adding the following to my persistence.xml file:

Code:
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />


and it appears to be disabled when the application starts:

Code:
16:43:41,839 INFO  [SettingsFactory] Second-level cache: disabled
16:43:41,840 INFO  [SettingsFactory] Query cache: disabled


but they have no effect.

I can hack around this by sprinkling entityManager.clear() and entityManager.refresh(c) throughout my code, but I'd prefer to set a configuration option and have the changes application wide.

Can someone point me in the right direction?

Thanks,
Dan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 23, 2008 11:07 pm 
Newbie

Joined: Mon Mar 31, 2008 2:37 pm
Posts: 6
Location: Seattle
can you pls put your hibernate properties as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 24, 2008 3:02 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The second-level cache has nothing to do with the first-level (session or persistence context) cache. The persistence context/session cache is mandatory for various reasons. In fact, not understanding this crucial part and ignoring it in application architecture is a recipe for disaster. There is no quick solution here, study some documentation.

(No need to post properties.)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 24, 2008 3:44 am 
Regular
Regular

Joined: Mon Aug 06, 2007 10:49 am
Posts: 67
Location: Banska Bystrica, Slovakia
either u will use refresh or evict object and then load them, or u can use stateless session but u will loose a lot o features http://www.hibernate.org/hib_docs/v3/re ... esssession


Top
 Profile  
 
 Post subject: Re: Disable Hibernate Session Cache (?)
PostPosted: Wed May 19, 2010 2:30 am 
Beginner
Beginner

Joined: Sat Jan 05, 2008 7:33 am
Posts: 26
> The second-level cache has nothing to do with the first-level (session or persistence context) cache. The persistence context/session cache is mandatory for various
> reasons. In fact, not understanding this crucial part and ignoring it in application architecture is a recipe for disaster. There is no quick solution here, study some documentation.

this remark might usually make a lot of sense but under certain circumstances the session cache might have very nasty side effects
what do you think the following sql query result would be when 2 separate threads execute roughly at the same time ?
String lockStr = "SELECT GET_LOCK('" + c + "_" + id + "',5)";
SQLQuery qq = sqlQuery(lockStr);
List<Object[]> res = qq.list();

my take would be that using the cache the user will be in great trouble because both queries will return 1 (I've got the lock) where they should definitely not !!!


Top
 Profile  
 
 Post subject: Re: Disable Hibernate Session Cache (?)
PostPosted: Fri May 20, 2011 8:58 am 
Newbie

Joined: Fri May 20, 2011 8:53 am
Posts: 1
Location: London
obourdon wrote:
this remark might usually make a lot of sense but under certain circumstances the session cache might have very nasty side effects
what do you think the following sql query result would be when 2 separate threads execute roughly at the same time ?
String lockStr = "SELECT GET_LOCK('" + c + "_" + id + "',5)";
SQLQuery qq = sqlQuery(lockStr);
List<Object[]> res = qq.list();

my take would be that using the cache the user will be in great trouble because both queries will return 1 (I've got the lock) where they should definitely not !!!


It's too late unfortunately) But anyway thanks)

_________________
android developers


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