Hibernate

From Documentation
Revision as of 11:32, 17 November 2010 by Tomyeh (talk | contribs) (Created page with '{{ZKDevelopersReferencePageHeader}} =Overview= Hibernate is an object-relational mapping (ORM) solution for the Java language. The main feature of Hibernate is that it simplifie…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

  1. Download hibernate core and hibernate annotations from Hibernate
  2. 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.

  1. Create zk.xml under $myApp/WEB-INF/(if not exists)
  2. 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

Last Update : 2010/11/17


Version Date Content
     



Last Update : 2010/11/17

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.