public class HibernateUtil
extends java.lang.Object
Holds Session and Transactions in thread local variables. All exceptions are wrapped in an unchecked HibernateUtilException.
| Modifier and Type | Class and Description |
|---|---|
static class |
HibernateUtil.HibernateUtilException |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
HIBERNATE_FILENAME_DEFAULT |
| Modifier and Type | Method and Description |
|---|---|
void |
beginTransaction()
Start a new database transaction.
|
static void |
clearInstance()
Nulls the instance field, so that subsequent calls to
getInstance(Logger) will create a new instance. |
void |
closeSession()
Closes the Session local to the thread.
|
void |
commitTransaction()
Commit the database transaction.
|
Session |
disconnectSession()
Disconnect and return Session from current Thread.
|
Configuration |
getConfiguration()
Returns the original Hibernate configuration.
|
static HibernateUtil |
getInstance(java.util.logging.Logger logger)
Singleton accessor
|
java.util.List |
getList(java.lang.Class type) |
Session |
getSession()
Retrieves the current Session local to the thread.
|
SessionFactory |
getSessionFactory()
Returns the SessionFactory used for this static class.
|
void |
rebuildSessionFactory()
Rebuild the SessionFactory with the static Configuration.
|
void |
rebuildSessionFactory(Configuration cfg)
Rebuild the SessionFactory with the given Hibernate Configuration.
|
void |
reconnect(Session session)
Reconnects a Hibernate Session to the current Thread.
|
void |
registerInterceptor(Interceptor interceptor)
Register a Hibernate interceptor with the current thread.
|
void |
rollbackTransaction()
Commit the database transaction.
|
void |
setConfiguration(Configuration config)
Set your own configuration and build session factory from it.
|
void |
setConfiguration(java.util.Properties extraProperties)
Use default configuration and add properties from Properties.
|
public static final java.lang.String HIBERNATE_FILENAME_DEFAULT
public static HibernateUtil getInstance(java.util.logging.Logger logger)
public static void clearInstance()
getInstance(Logger) will create a new instance.
This probably only makes sense between junit tests that want to start out fresh.public void setConfiguration(java.util.Properties extraProperties)
config - public void setConfiguration(Configuration config)
config - public SessionFactory getSessionFactory()
public Configuration getConfiguration()
public void rebuildSessionFactory()
throws HibernateUtil.HibernateUtilException
public void rebuildSessionFactory(Configuration cfg)
throws HibernateUtil.HibernateUtilException
cfg - HibernateUtil.HibernateUtilExceptionpublic Session getSession()
throws HibernateUtil.HibernateUtilException
HibernateUtil.HibernateUtilExceptionpublic void closeSession()
throws HibernateUtil.HibernateUtilException
public void beginTransaction()
throws HibernateUtil.HibernateUtilException
public void commitTransaction()
throws HibernateUtil.HibernateUtilException
public void rollbackTransaction()
throws HibernateUtil.HibernateUtilException
public void reconnect(Session session)
throws HibernateUtil.HibernateUtilException
session - The Hibernate Session to be reconnected.HibernateUtil.HibernateUtilExceptionpublic Session disconnectSession()
throws HibernateUtil.HibernateUtilException
HibernateUtil.HibernateUtilExceptionpublic void registerInterceptor(Interceptor interceptor)
Every Session opened is opened with this interceptor after registration. Has no effect if the current Session of the thread is already open, effective on next close()/getSession().
public java.util.List getList(java.lang.Class type)
throws HibernateUtil.HibernateUtilException