Hibernate
From Documentation
Overview
Hibernate is an object-relational mapping (ORM) solution for the Java language. The main feature of Hibernate is that it simplifies the job of accessing a database.
Example here we use with Hibernate 3.3 and hsqldb 1.8. It shall work with the newer version.
Installing Hibernate
Before using Hibernate, you have to install it into your application first.
- Download hibernate core and hibernate annotations from Hibernate
- Put *.jar files from hibernate core and hibernate annotations into your $myApp/WEB-INF/lib/
$myApp represents the name of your web application. ex. event
Configuring the ZK Configuration File
To make ZK works with Hibernate smoothly, you have to use the following utilities.
- Create zk.xml under $myApp/WEB-INF/(if not exists)
- Copy the following lines into your zk.xml
<!-- Hibernate SessionFactory lifecycle -->
<listener>
<description>Hibernate SessionFactory lifecycle</description>
<listener-class>org.zkoss.zkplus.hibernate.HibernateSessionFactoryListener</listener-class>
</listener>
<!-- Hibernate OpenSessionInView Pattern -->
<listener>
<description>Hibernate Open Session In View life-cycle</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>
$myApp represents the name of your web application. ex. event
Creating the Java Objects
Mapping the Java Objects
Creating the Hibernate Configuration File
Creating DAO Objects
Accessing Persistence Objects in ZUML Page
Version History
Version | Date | Content |
---|---|---|