-->
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.  [ 1 post ] 
Author Message
 Post subject: Detecting when to call session.flush()
PostPosted: Mon Jun 27, 2011 4:33 am 
Newbie

Joined: Mon Jun 27, 2011 3:59 am
Posts: 1
Hello,

I am improving the performance of an existing system. Session.flush() is showing up as one of the hotspots. The code has many (at least 100) methods that follow this pattern:

Code:
public void foo()
{
  try
  {
    Session session = getSession();
    //do some work with the session
  }
  finally
  {
    closeSession(session)
  }
}


The problem is that the helper method "closeSession" is always calling session.flush(), just before session.close(), regardless of what work was done on the session.

My understanding is that you should call session.flush() before session.close() only when non read-only work was done on the session in question. is this correct?

I could remove the session.flush() call from the closeSession() method then inspect every method, like the one above, and add in the session.flush() just to those that are not read-only. However, there are over 100 such methods, so this approach is likely to lead to errors and likely to be forgotten for new methods of the type above.

Is there a way of having hibernate flush the session on close only if changes have been made?

Thanks,

Paul.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.