-->
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 Cahching mechanism
PostPosted: Mon Feb 28, 2011 4:14 am 
Newbie

Joined: Mon Feb 28, 2011 4:06 am
Posts: 1
I have a quick question. could any one answer ?

1) what are the difference between first level cache and second level cache in hibernate ?
Now i have my data in first or second level cache, if some other application operated on the same data in db, will that changed data reflect in my cache. if not, how to handle that type of situation.

--Regards
Dhanunjay Reddy V


Top
 Profile  
 
 Post subject: Re: Hibernate Cahching mechanism
PostPosted: Mon Feb 28, 2011 5:54 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
First level cache is only used by the current session. As soon as you close session that cache is cleared. You can also clear first level cache without closing session, by explicitly calling session.clear().

Second level cache is used for multiple sessions. If you close a session, loaded objects remain in the second level cache and may be loaded from there (instead of being loaded from the database), if a new session happens to query one of these objects again. Second level cache is bound to the SessionFactory. If you decide to use second level cache you must not modify your database other than using sessions acquired from your session factory. If you do, you risk getting a StaleObjectException. Second level cache is usually not practically usable, if you have a two tier application (cllient directly accessing database).


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.