public class HibernateUtil extends Object
Utility to access Hibernate Session. This implementation works with the Hibernate's thread session context (version 3.1+). That is, you have to specified hibernate's configuration file "hibernate.cfg.xml" to as follows:
<session-factory> ... <property name="current_session_context_class">thread</property> </session-factory>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-FILENAME</value>Also notice that the zkplus.jar must be put under application's WEB-INF/lib because the SessionFactory is stored as a class static member.
Applicable to Hibernate version 3.2.ga or later
| Modifier and Type | Field and Description |
|---|---|
static String |
CONFIG
Deprecated.
A preference or a library property used to configure
HibernateUtil. |
| Constructor and Description |
|---|
HibernateUtil()
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
closeSession()
Deprecated.
Wrapping HibernateUtil.getSessionFactory().getCurrentSession().close() into a simple API.
|
static org.hibernate.Session |
currentSession()
Deprecated.
Wrapping HibernateUtil.getSessionFactory().getCurrentSession() into a simple API.
|
static org.hibernate.SessionFactory |
getSessionFactory()
Deprecated.
Get the singleton hibernate Session Factory.
|
public static final String CONFIG
HibernateUtil.
It first looks up Configuration.getPreference(java.lang.String, java.lang.String), and then
Library.getProperty(java.lang.String). Ignored if none of them is specified.public static org.hibernate.SessionFactory getSessionFactory()
public static org.hibernate.Session currentSession()
throws org.hibernate.HibernateException
org.hibernate.HibernateExceptionpublic static void closeSession()
throws org.hibernate.HibernateException
org.hibernate.HibernateExceptionCopyright © 2015. All rights reserved.