-->
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.  [ 3 posts ] 
Author Message
 Post subject: session.flush() usage and issues
PostPosted: Thu Jun 01, 2006 4:54 am 
Newbie

Joined: Thu Jun 01, 2006 3:17 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate3.0.1

Oracle9i

Hi Guys,

We have problem with session.flush() usage.We are using the session-per-request pattern.We call session.flush() even when we are fetching objects from DB and also when are persisting them to DB.My question is should we explicitly call session.flush() when we are listing the objects using query.list() , session.get() ,criteria.list() calls ?What is the ideal scenario where it has to be called ?How should we keep our session in sync with DB always ?

Thanks ,
Neil.
OSI Technologies.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 6:07 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Usually you dont need to call session.flush(). Especially in the cases you mentioned.

session.flush() is useful in cases you need the primary key for further processing (before the commit).

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 7:48 am 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
If you're using the session-per-request pattern with Hibernates contextual sessions and you're using the default FlushMode of AUTO, Hibernate will automatically flush the session when one of the following happens:

    The Transaction is commited
    A Query is executed
    You explicitly call session.flush()


With the defaults, Hibernate will make sure you're not making dirty reads and this is how Hibernate automagically keeps your session in sync.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


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