|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.extras.hibernate.SessionContext
Provides a thread local Hibernate Session context class. The Hibernate configuration should be defined in class path file:
/hibernate.cfg.xmlOr alternatively by using System properties. The Hibernate initialization code used by SessionContext is:
Configuration configuration = createConfiguration(); configuration.setProperties(System.getProperties()); configuration.configure(); SessionFactory sessionFactory = configuration.buildSessionFactory();To support the SessionContext class configure a
SessionFilter
in
your web application.
SessionFilter
,
HibernateForm
Constructor Summary | |
SessionContext()
|
Method Summary | |
static void |
close()
Close the Session held by the current Thread. |
org.hibernate.cfg.Configuration |
createConfiguration()
Creates and returns a new Configuration instance. |
static org.hibernate.Session |
getSession()
Get the Session for the current Thread, creating one if necessary. |
static org.hibernate.SessionFactory |
getSessionFactory()
Return the Hibernate SesssionFactory. |
static boolean |
hasSession()
Return true if a session is open. |
void |
initConfiguration(org.hibernate.cfg.Configuration configuration)
Initialize the configuration instance. |
void |
onInit(ServletContext servletContext)
Initializes the SessionContext instance. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SessionContext()
Method Detail |
public void onInit(ServletContext servletContext)
createConfiguration()
and then initializes the configuration
by invoking initConfiguration(org.hibernate.cfg.Configuration)
.
servletContext
- the servlet contextpublic org.hibernate.cfg.Configuration createConfiguration()
public void initConfiguration(org.hibernate.cfg.Configuration configuration)
public Configuration createConfiguration() { configuration.setProperties(System.getProperties()); configuration.configure(); }
configuration
- the configuration to initializepublic static org.hibernate.Session getSession() throws org.hibernate.HibernateException
org.hibernate.HibernateException
- if an error occurs opening the sessionpublic static void close() throws org.hibernate.HibernateException
org.hibernate.HibernateException
- if an error occurs closing the sessionpublic static boolean hasSession()
public static org.hibernate.SessionFactory getSessionFactory()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |