ajax.database
Class HibernateFactory

java.lang.Object
  extended by ajax.database.HibernateFactory

public class HibernateFactory
extends java.lang.Object

This is the Hibernate Entity Manager factory for the entire application. This class maintains a single EntityManager object that can be retrieved and used througout the application such that persistant classes will remain connected (non-transient).

Author:
Adam Kaplan

Field Summary
static java.lang.ThreadLocal<javax.persistence.EntityManager> em
          The single entity manager for this application instance
static javax.persistence.EntityManagerFactory emf
          The entity manager factory for generating entity manager
 
Constructor Summary
HibernateFactory()
           
 
Method Summary
static void closeSession()
          Close the currently opened EntityManger
static void commit(org.hibernate.Transaction tx)
          This is a simple method to reduce the amount of code that needs to be written every time hibernate is used.
static javax.persistence.EntityManagerFactory getEmf()
           
static javax.persistence.EntityManager getSession()
          Retrieve or create the entity manager
static void rollback(org.hibernate.Transaction tx)
          This is a simple method to reduce the amount of code that needs to be written every time hibernate is used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

emf

public static final javax.persistence.EntityManagerFactory emf
The entity manager factory for generating entity manager


em

public static final java.lang.ThreadLocal<javax.persistence.EntityManager> em
The single entity manager for this application instance

Constructor Detail

HibernateFactory

public HibernateFactory()
Method Detail

getSession

public static javax.persistence.EntityManager getSession()
                                                  throws org.hibernate.HibernateException
Retrieve or create the entity manager

Returns:
A new or existing EntityManager for this application
Throws:
org.hibernate.HibernateException - If there is a problem

closeSession

public static void closeSession()
                         throws org.hibernate.HibernateException
Close the currently opened EntityManger

Throws:
org.hibernate.HibernateException - If there is a problem

getEmf

public static javax.persistence.EntityManagerFactory getEmf()
Returns:
the hibernate session factory

rollback

public static void rollback(org.hibernate.Transaction tx)
This is a simple method to reduce the amount of code that needs to be written every time hibernate is used.


commit

public static void commit(org.hibernate.Transaction tx)
This is a simple method to reduce the amount of code that needs to be written every time hibernate is used.