-->
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: Hibernate caching objects?
PostPosted: Sat Oct 28, 2006 3:20 pm 
Newbie

Joined: Sat Oct 28, 2006 3:05 pm
Posts: 10
To begin with, I'm sorry if this question has been here before but I didn't find it.
I'm a really new Hibernate user, and I have this problem - I execute a query, and get a list of objects. I change some of the objects in the database, possibly by another client. Then, when I execute the query again, Hibernate fetches all the objects again, but doesn't refresh their contents - they don't reflect the database changes. Refreshig happens only if I iterate through the returned list, and call Session.refresh on the objects. I have logging massages which tell me that the SQL for retrieving objects is invoked against the database, and when I call refresh, Hibernate fetches the objects again, one SQL query for each of the iterated objects.
It looks as if the objects are cached somewhere under the hood, and when I call the query which fetches all objects again, they are looked up in the cache (using the id or something) and if a corresponding object is found, it isn't refreshed. When I call Session.refresh with this object, it is refreshed, as I would like.
So my question is - do I have something misconfigured? Or can I switch this caching off somehow? Or maybe this is the desired procedure - call refresh on the objects?
Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 29, 2006 2:55 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
You are correct, and if you look at the hibernate docs, you'll learn a lot about how the cache behaves. In your case, the cache is not the issue - lazy init of objects is. Lazy init is the default behavior of Hibernate and you should familiarize with it asap in order to really KNOW what needs to be lazy-initialized and what should not.
For testing purposes only, you can tag all your classes with "lazy=false" and all collections with lazy="false" - just to see that this time, the query happens immediately, but I would not advise to leave it like this for production environments:
Code:
<class ... lazy="false">
...
    <map|list|set|  .... lazy=false>
</class>


(p.s. please rate if this was helpful :-) ... )


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.