i am using the open-session-in-view pattern. i have an ActionFilter that exposes a static getConnection() method. I open the connection in my Struts Action class, save the data in a 'DAO' layer (pass the session as a param), and the session should be closing in the finally block of my ActionFilter.
ActionFilter
Code:
// in doFilter() method
try
{
chain.doFilter( request, response );
}
finally
{
try
{
HibernateSession.closeSession();
}
catch( Exception e )
{
log.error( "Error closing database connection.", e );
e.printStackTrace();
}
} //end doFilter
public static Session getConnection() throws Exception
{
return HibernateSession.currentSession();
}
Struts 'Action' class
Code:
Campaign cmp = dm.getCampaign( frm.getCampaignId(), ActionFilter.getConnection() );
And in the DAO class...
Code:
ses.saveOrUpdate( obj );
ses.flush();
ses.connection().commit();
if i am am implementing the pattern correctly i should be opening and closing sessions properly. What do you think.
thanks again.