Hi, all
I'm using hibernate in my web app on jboss application server.
To avoid initialization delay (configuring, opening session, ect) on each jsp I save the object which encapsulated all hibernate data (HibernateLibBean) in HttpSession.
Code:
public HibernateLibBean getHib(HttpSession http_ses, String str_connector, String str_ip) throws Exception
{
HibernateLibBean hib = (HibernateLibBean) http_ses.getAttribute(HIB_PROP_NAME);
try
{
if( hib == null )
{
//this code executed only once
hib = new HibernateLibBean();
hib.sys_init(str_connector, str_ip);
http_ses.setAttribute(HIB_PROP_NAME, hib);
}
}
catch(Exception ex)
{
throw ex;
}
return hib;
}
and later on each jsp
Code:
HibernateLibBean hib = hib_loader.getHib(session,"connector_test.jar", request.getRemoteAddr() );
This brings me a very fast initialization.
HibernateLibBean has method finalize(). The purpose of this method is to close all hibernate connection with database.
It works, But i want to hear your comment.
Maybe exist a better solution for this problem.
Thanks for your comments.
Hibernate version: 2.1.4
Name and version of the database you are using: postgresql 7.3.6 RH