I'm attempting to debug some previously developed code that appears to have been written session-per-operation style, and we're continually seeing 1) performance issues and 2) Lock Acquisition Exceptions (LAE). Of course, being that it's session-per-operation style, all of the DAOs (about 50 or so) all have session management embedded. In one particular case, we have a simple call to save one row to one table that results in updates to other rows in the same table (as well as a few other updates in other tables) then retrieves the inserted record back by doing another get from a new session, and this regularly gets an LAE - which doesn't surprise me. I've tried wrapping this in a transaction (because it wasn't before), but the exception persists. We've even received this except during read-only requests due to write-locks still active (we can replicate this during load testing where we save repetitively and try to load a read-only view of the page containing newly saved posts).
We're using Spring 2.0, Hibernate 3, and MS SQL 2005. The Model classes are annotated, and Hibernate and DAOs are configured via Spring XML applicationContexts. I'm truly at a loss to resolve these recurring problems in a way that doesn't require us to rewrite every DAO, site-wide, immediately. I'm not sure if there's a quick, temporary way to set transaction levels, to hopefully bypass the LAE problem while we work on rewriting the app and DAOs to be session-per-request.
Example DAO Method
Code:
public void savePost(Post post) {
Session session = getSession();
Transaction tx = session.beginTransaction();
try{
getHibernateTemplate().saveOrUpdate(post);
tx.commit();
}catch(Exception e){
tx.rollback();
}finally{
releaseSession(session);
}
}
Any suggestions would be greatly appreciated.