-->
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: clear session before execute criteria
PostPosted: Sat May 03, 2008 1:53 am 
Beginner
Beginner

Joined: Wed Oct 03, 2007 9:46 pm
Posts: 37
whenever calling criteria, i will clear the session first . the reason i doing this is to ensure whathever records i grab from database is the latest. is there any side effects of too frequent use of clear session?






Code:

Session sess = HibernateSessionFactory.currentSession();
            sess.clear();

            Criteria crit = sess.createCriteria(myClass.class,"class")



Top
 Profile  
 
 Post subject: clear session before execute criteria
PostPosted: Sat May 03, 2008 8:08 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

Clearing the session each time means you won't be able to take advantage of the IdentityMap (sometimes referred to as the 1st level cache).

If there are pending changes that have been made through NHibernate, and the session flush-mode is automatic (the default), then NHibernate is intelligent enough to flush out pending changes before executing the query.

Alternatively you could use session.Flush() before the query to ensure any pending records are written.

Regards,
Richard


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.