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.