Revision history [back]

click to hide/show revision 1
initial version

asked 2009-11-26 20:59:18 +0800

hawk gravatar image hawk

http://hawkphoenix.blogsp... ZK Team

can I use getHibernateTemplate() with org.zkoss.zkplus.hibernate.HibernateSessionContextListener?

Hi pals here, I encounter lazy initialization problem of Hibernate. I have set zk.xml according to small talk "ZK + Hibernate", http://www.zkoss.org/smalltalks/hibernatezk/hibernatezk.dsp

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

<!-- Configure the Hibernate "Open Session In View" Session Lifecycle -->
<listener>
    <description>Hibernate "Open Session In View" Session Lifecycle</description>
    <listener-class>org.zkoss.zkplus.hibernate.OpenSessionInViewListener</listener-class>
</listener>


<!-- Hibernate thread session context handler -->
<listener>
    <description>Hibernate thread session context handler</description>
    <listener-class>
        org.zkoss.zkplus.hibernate.HibernateSessionContextListener
    </listener-class>
</listener>

hibernate.cfg.xml <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.password">hr</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/hr</property> <property name="hibernate.connection.username">hr</property> <property name="hibernate.default_schema">hr</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.current_session_context_class">thread</property> <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

My all DAO class all extends Spring's HibernateDaoSupport.

public abstract class AbstractDAO extends HibernateDaoSupport{ public void saveOrUpdate(Object obj) {

    getHibernateTemplate().saveOrUpdate(obj);
}

public void delete(Object obj) {
    getHibernateTemplate().delete(obj);
}

}

I have tried, if I use getHibernateTemplate() to query, I will get "lazy initialization.. session closed" problem. But, if I use getSession().createQuery() to query, it works normally.

so, it means I can't use getHibernateTemplate() with ZK? what's the reason?

Thanks for help.

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More