@com.google.inject.Singleton @groovy.util.logging.Slf4j class SessionManager extends java.lang.Object implements java.io.Closeable
Created so that we can have more granular control over when the database session closes. Using SessionFactory.currentSession() is convenient, but it closes the session after every commit. This makes it impossible to have lazy loaded associations as the session needs to be open to fetch associated rows from the database. We also need to have control over when transactions actually begin and end. We have to roll up our sleeves and commit to building a true session-per-request model.
Constructor and description |
---|
SessionManager(org.hibernate.SessionFactory sessionFactory) |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
beginTransaction() Start a transaction. |
|
void |
close() Close the session completely. |
|
void |
commit() Commit any existing transactions. |
|
org.hibernate.Session |
getSession()
|
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |