-->
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: Hibernate caches queries an give obsolete data back
PostPosted: Tue Mar 28, 2006 10:33 am 
Newbie

Joined: Fri Oct 22, 2004 4:00 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1.7

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:Oracle 9i EE

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Hi Folks,
I hope someone can help me with the following problem.

I am using the following query to get users by their status from the database:

<query name="RmsBenutzer.findByStatus">
<![CDATA[
from RmsBenutzer u where u.status = :status order by upper(u.login)
]]>
</query>

I get the userlist without any problem. Now when I change a user attribute (let's say his firstname) and query the database again, i get alternatively the previous and the new value. The new value is saved to DB without any problem.
When i change the value(firstname) four times for example, the following queries return one of the four values randomly.

I played with the cache issues to solve the problem with out any success.

I tried this too:




Code:
Session sess = SessionFactoryHelper.getCurrentSession();
Query q = sess.createQuery("from RmsBenutzer where status = "+status.intValue()+" order by upper(login)");
q.setCacheRegion("CacheRegionOfTheRMSUserList");
         q.setForceCacheRefresh(true);         
         List testuserlist = q.list();
         sess.flush();


without any success.

For Information my application is running on SAP WAS and i am using the
DB-Connection through a datasource.

Thank you for nay help.

Alioum


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 1:08 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
if you are requerying through the same "session" object, and not updating through that same "session" object, then your experience is consistent with how hibernate works.

If you are "updating" via, 3rd party tool, like TOAD or SQLPLUS or any command line tool, then your experience is consistent with how hibernate works - regardless of your cache settings. You need to invalidate the cache - close your session and in your sessionfactory call evict methods to clear out the cache for the objects that changed.

Also, notice that if you are worried about concurrent updates to the same object, then you should setup "versioning" on your objects. Look into the "<version...>" tag on your class mapping.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 1:10 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
one last thing is that you may be issuing "session.save" vs. session.saveOrUpdate on your objects - and make sure your unsaved-values="null" on your PK. This might explain the "insert" of a new record vs. an update of existing...

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 9:15 am 
Newbie

Joined: Fri Oct 22, 2004 4:00 pm
Posts: 5
Hi jt_1000,
thx for your wonderful help. I just closed the session after querying the list and it worked!!!!
here are the 3 lines which make me smile...

Code:
sess.flush
sess.clear();
sess.close();


have a nice day



[quote="jt_1000"]if you are requerying through the same "session" object, and not updating through that same "session" object, then your experience is consistent with how hibernate works.

If you are "updating" via, 3rd party tool, like TOAD or SQLPLUS or any command line tool, then your experience is consistent with how hibernate works - regardless of your cache settings. You need to invalidate the cache - close your session and in your sessionfactory call evict methods to clear out the cache for the objects that changed.

Also, notice that if you are worried about concurrent updates to the same object, then you should setup "versioning" on your objects. Look into the "<version...>" tag on your class mapping.


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.