-->
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.  [ 2 posts ] 
Author Message
 Post subject: Flush session and get latest values from DB
PostPosted: Mon Mar 21, 2011 5:34 pm 
Newbie

Joined: Tue Aug 14, 2007 2:46 am
Posts: 7
I am currently using Spring, Hibernate and JUnit and EhCache. I am trying to do the following:

1) Hibernate Session 1: select X from test where id = 1 //X = 100
2) JDBC Session: update test set x=25 where id =1
3) Hibernate Session 1: select X from test where id = 1 //X IS STILL 100?

How can i get hibernate to pick up my change once i change the DB on the back-end.

ps. I am trying to test caching here and want to update the database, and then want to hit cache.removeAll() and the new values x=25 to be picked up. Any clue how i can do this?


Top
 Profile  
 
 Post subject: Re: Flush session and get latest values from DB
PostPosted: Wed Mar 23, 2011 8:45 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
every session has a first-level cache, so once an object gets loaded from the DB, it is in the cache and is returned if you query for that again.
you have to call session.evict(yourObject) to detach this object from the session or session.clear() to detach all managed objects from the session.

_________________
-----------------
Need advanced help? http://www.viada.eu


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