diff --git a/reference/en/modules/configuration.xml b/reference/en/modules/configuration.xml index 4b0e9c1e9e..20f63bb096 100644 --- a/reference/en/modules/configuration.xml +++ b/reference/en/modules/configuration.xml @@ -1602,16 +1602,15 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect]]> - + Automatic JTA and Session binding - For non-managed environments we suggested HibernateUtil with - a static SessionFactory, and ThreadLocal - management of the Hibernate Session. This approach isn't easy - to use in an EJB environment, as several EJB's may execute inside the same - transaction but not the same thread. We recommend that you bind the - SessionFactory to JNDI in a managend environment. + We recommend that you bind the SessionFactory to JNDI in + a managend environment. For transaction and Session handling, + you could use the already introduced HibernateUtil helper class. + However, EJBs might not execute in the same thread, which makes ThreadLocal + handling not always appropriate (e.g. when two session beans call each other). @@ -1623,7 +1622,11 @@ hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect]]> and hibernate.transaction.auto_close_session configuration option, will be set automatically for every Session you retrieve with getCurrentSession(), so they will also be flushed and closed - automatically when the container ends the JTA transactions. + automatically when the container ends the JTA transactions. This is an alternative + to ThreadLocal management. The HibernateUtil + class you can find with the CaveatEmptor application can + actually switch between both strategies automatically, hence, keeps your code + portable between transaction-local, BMT, and CMT environments. diff --git a/reference/en/modules/quickstart.xml b/reference/en/modules/quickstart.xml index 759ff72992..ead7c5925c 100644 --- a/reference/en/modules/quickstart.xml +++ b/reference/en/modules/quickstart.xml @@ -442,7 +442,7 @@ Indexes: cat_pkey primary key btree (cat_id)]]> - + Playing with cats @@ -503,7 +503,7 @@ public class HibernateUtil { public static final ThreadLocal session = new ThreadLocal(); - public static Session currentSession() { + public static Session getCurrentSession() { Session s = (Session) session.get(); // Open a new Session, if this Thread has none yet if (s == null) { @@ -539,7 +539,7 @@ public class HibernateUtil { process() method might look like this (sans exception handling): - - Note that you may call HibernateUtil.currentSession(); + Note that you may call HibernateUtil.getCurrentSession(); as many times as you like, you will always get the current Session of this thread. You have to make sure the Session is closed after your unit-of-work completes, either in your servlet code or in a servlet filter diff --git a/reference/en/modules/transactions.xml b/reference/en/modules/transactions.xml index 6203d70fc1..ba6e803dfc 100644 --- a/reference/en/modules/transactions.xml +++ b/reference/en/modules/transactions.xml @@ -56,7 +56,7 @@ database transaction boundaries? - + Unit of work @@ -92,10 +92,9 @@ easy access (like accessing a static variable) in all code that runs in this thread. Depending on the database transaction demarcation mechanism you chose, you might also keep the transaction context in a ThreadLocal variable. The implementation patterns for this - are known as ThreadLocal Session and Open Session in View. - You can easily extend the HibernateUtil helper class shown earlier in this - documentation to implement this. Of course, you'd have to find a way to implement an interceptor - and set it up in your environment. See the Hibernate website for tips and examples. + are known as ThreadLocal Session and Open Session in View + and can be found on the Hibernate Wiki. Of course, you'd have to find a way to implement an + interceptor and set it up in your environment. See the Hibernate website for tips and examples. diff --git a/reference/en/modules/tutorial.xml b/reference/en/modules/tutorial.xml index c2cdcad4d6..227b223046 100644 --- a/reference/en/modules/tutorial.xml +++ b/reference/en/modules/tutorial.xml @@ -478,7 +478,7 @@ Total time: 1 second ]]> - + Startup and helpers @@ -518,7 +518,7 @@ public class HibernateUtil { public static final ThreadLocal session = new ThreadLocal(); - public static Session currentSession() throws HibernateException { + public static Session getCurrentSession() throws HibernateException { Session s = (Session) session.get(); // Open a new Session, if this thread has none yet if (s == null) { @@ -542,7 +542,7 @@ public class HibernateUtil { its static initializer (called once by the JVM when the class is loaded), but also has a ThreadLocal variable to hold the Session for the current thread. No matter when you call - HibernateUtil.currentSession(), it will always return the same + HibernateUtil.getCurrentSession(), it will always return the same Hibernate unit of work in the same thread. A call to HibernateUtil.closeSession() ends the unit of work currently associated with the thread. @@ -592,7 +592,7 @@ build.xml]]> - + Loading and storing objects @@ -625,7 +625,7 @@ public class EventManager { - + Working the association @@ -934,7 +934,7 @@ else if (args[0].equals("list")) {