org.zkoss.zkplus.hibernate
Class HibernateSessionFactoryListener

java.lang.Object
  extended by org.zkoss.zkplus.hibernate.HibernateSessionFactoryListener
All Implemented Interfaces:
java.util.EventListener, javax.servlet.ServletContextListener, WebAppCleanup, WebAppInit

Deprecated. As of release 6.0.2, please use the official Hibernate's method instead.

public class HibernateSessionFactoryListener
extends java.lang.Object
implements WebAppInit, WebAppCleanup, javax.servlet.ServletContextListener

Listener to init and cleanup the hibernate session factory automatically. This listener is used with OpenSessionInViewListener and HibernateUtil, or it will not work.

In WEB-INF/zk.xml, add following lines:


        <listener>
                <description>Hibernate SessionFactory Lifecycle</description>
                <listener-class>org.zkoss.zkplus.hibernate.HibernateSessionFactoryListener</listener-class>
        </listener>
 

Since ZK 3.0.1, if your hibernate configuration file name is not the default "hibernate.cfg.xml", you can specify it in WEB-INF/zk.xml. Just add following lines:


        <preference>
        <name>HibernateUtil.config</name>
        <value>YOUR-HIBERNATE-CONFIG-FILENAME</value>
 

Sometimes, when using ZK with other backend framework, the Hibernate's SessionFactory might has to be created earlier. Therefore, since ZK 3.0.1, we have implemented this listener to be also a ServletContextListener that you can choose to specify it in web.xml instead and make it initialized right when your applcation is deployed.

In WEB-INF/web.xml, add following lines:


        <context-param>
                <param-name>HibernateUtil.config</param-name>
                <param-value>YOUR-HIBERNATE-CONFIG-FILENAME</param-value>
        </context-param>
        <listener>
                <listener-class>org.zkoss.zkplus.hibernate.HibernateSessionFactoryListener</listener-class>
        </listener>
 

Applicable to Hibernate version 3.2.ga or later

Author:
henrichen

Constructor Summary
HibernateSessionFactoryListener()
          Deprecated.  
 
Method Summary
 void cleanup(WebApp wapp)
          Deprecated. called when a ZK application is about to be destroyed.
 void contextDestroyed(javax.servlet.ServletContextEvent sce)
          Deprecated.  
 void contextInitialized(javax.servlet.ServletContextEvent sce)
          Deprecated.  
 void init(WebApp app)
          Deprecated. Called when a ZK application is created and initialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernateSessionFactoryListener

public HibernateSessionFactoryListener()
Deprecated. 
Method Detail

init

public void init(WebApp app)
Deprecated. 
Description copied from interface: WebAppInit
Called when a ZK application is created and initialized.

You could retrieve the servlet context by WebApp.getServletContext()

Specified by:
init in interface WebAppInit

cleanup

public void cleanup(WebApp wapp)
Deprecated. 
Description copied from interface: WebAppCleanup
called when a ZK application is about to be destroyed.

If this method throws an exception, the error message is only logged (user won't see it).

Specified by:
cleanup in interface WebAppCleanup

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent sce)
Deprecated. 
Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener
Since:
3.0.1

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent sce)
Deprecated. 
Specified by:
contextInitialized in interface javax.servlet.ServletContextListener
Since:
3.0.1


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo