public class GrailsHibernateTemplate
Modifiers | Name | Description |
---|---|---|
protected class |
GrailsHibernateTemplate.CloseSuppressingInvocationHandler |
Invocation handler that suppresses close calls on Hibernate Sessions. |
static interface |
GrailsHibernateTemplate.HibernateCallback |
Modifiers | Name | Description |
---|---|---|
static int |
FLUSH_ALWAYS |
Flushing before every query statement is rarely necessary. |
static int |
FLUSH_AUTO |
Automatic flushing is the default mode for a Hibernate Session. |
static int |
FLUSH_COMMIT |
Flushing at commit only is intended for units of work where no intermediate flushing is desired, not even for find operations that might involve already modified instances. |
static int |
FLUSH_EAGER |
Eager flushing leads to immediate synchronization with the database, even if in a transaction. |
static int |
FLUSH_NEVER |
Never flush is a good strategy for read-only units of work. |
protected boolean |
allowCreate |
|
protected boolean |
cacheQueries |
|
protected boolean |
checkWriteOperations |
|
protected boolean |
exposeNativeSession |
|
protected int |
flushMode |
|
protected org.springframework.jdbc.support.SQLExceptionTranslator |
jdbcExceptionTranslator |
|
protected org.hibernate.SessionFactory |
sessionFactory |
Constructor and description |
---|
protected GrailsHibernateTemplate
() |
GrailsHibernateTemplate
(org.hibernate.SessionFactory sessionFactory) |
GrailsHibernateTemplate
(org.hibernate.SessionFactory sessionFactory, HibernateDatastore datastore) |
GrailsHibernateTemplate
(org.hibernate.SessionFactory sessionFactory, HibernateDatastore datastore, int defaultFlushMode) |
Type | Name and description |
---|---|
protected org.hibernate.FlushMode |
applyFlushMode(org.hibernate.Session session, boolean existingTransaction) Apply the flush mode that's been specified for this accessor to the given Session. |
void |
applySettings(org.hibernate.Query query) |
void |
applySettings(org.hibernate.Criteria criteria) |
void |
clear() |
boolean |
contains(java.lang.Object entity) |
protected org.springframework.dao.DataAccessException |
convertHibernateAccessException(org.hibernate.HibernateException ex) |
protected org.springframework.dao.DataAccessException |
convertJdbcAccessException(org.hibernate.JDBCException ex, org.springframework.jdbc.support.SQLExceptionTranslator translator) |
protected org.hibernate.Session |
createSessionProxy(org.hibernate.Session session) Create a close-suppressing proxy for the given Hibernate Session. |
void |
delete(java.lang.Object entity) |
void |
deleteAll(java.util.Collection<?> objects) |
protected T |
doExecute(HibernateCallback<T> action, boolean enforceNativeSession) Execute the action specified by the given action object within a Session. |
void |
evict(java.lang.Object entity) |
T |
execute(groovy.lang.Closure<T> callable) |
T |
execute(HibernateCallback<T> action) |
java.util.List<?> |
executeFind(HibernateCallback<?> action) |
void |
flush(java.lang.Object entity) |
void |
flush() |
protected void |
flushIfNecessary(org.hibernate.Session session, boolean existingTransaction) |
T |
get(java.lang.Class<T> entityClass, java.io.Serializable id) |
T |
get(java.lang.Class<T> entityClass, java.io.Serializable id, org.hibernate.LockMode mode) |
int |
getFlushMode() Return if a flush should be forced after executing the callback code. |
protected java.util.Collection |
getIterableAsCollection(java.lang.Iterable objects) |
protected org.hibernate.Session |
getSession() |
org.hibernate.SessionFactory |
getSessionFactory() |
boolean |
isApplyFlushModeOnlyToNonExistingTransactions() |
boolean |
isCacheQueries() |
boolean |
isExposeNativeSession() |
boolean |
isOsivReadOnly() |
protected boolean |
isSessionTransactional(org.hibernate.Session session) |
T |
load(java.lang.Class<T> entityClass, java.io.Serializable id) |
java.util.List<T> |
loadAll(java.lang.Class<T> entityClass) |
T |
lock(java.lang.Class<T> entityClass, java.io.Serializable id, org.hibernate.LockMode lockMode) |
void |
lock(java.lang.Object entity, org.hibernate.LockMode lockMode) |
protected void |
prepareCriteria(org.hibernate.Criteria criteria) Prepare the given Criteria object, applying cache settings and/or a transaction timeout. |
protected void |
prepareQuery(org.hibernate.Query query) Prepare the given Query object, applying cache settings and/or a transaction timeout. |
void |
refresh(java.lang.Object entity) |
void |
refresh(java.lang.Object entity, org.hibernate.LockMode lockMode) |
java.io.Serializable |
save(java.lang.Object o) |
void |
setApplyFlushModeOnlyToNonExistingTransactions(boolean applyFlushModeOnlyToNonExistingTransactions) |
void |
setCacheQueries(boolean cacheQueries) |
void |
setExposeNativeSession(boolean exposeNativeSession) |
void |
setFlushMode(int flushMode) Set the flush behavior to one of the constants in this class. |
void |
setOsivReadOnly(boolean osivReadOnly) |
protected boolean |
shouldPassReadOnlyToHibernate() |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), 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() |
Flushing before every query statement is rarely necessary. It is only available for special needs.
In case of an existing Session, FLUSH_ALWAYS will turn the flush mode to ALWAYS for the scope of the current operation, resetting the previous flush mode afterwards.
Automatic flushing is the default mode for a Hibernate Session. A session will get flushed on transaction commit, and on certain find operations that might involve already modified instances, but not after each unit of work like with eager flushing.
In case of an existing Session, FLUSH_AUTO will participate in the existing flush mode, not modifying it for the current operation. This in particular means that this setting will not modify an existing flush mode NEVER, in contrast to FLUSH_EAGER.
Flushing at commit only is intended for units of work where no intermediate flushing is desired, not even for find operations that might involve already modified instances.
In case of an existing Session, FLUSH_COMMIT will turn the flush mode to COMMIT for the scope of the current operation, resetting the previous flush mode afterwards. The only exception is an existing flush mode NEVER, which will not be modified through this setting.
Eager flushing leads to immediate synchronization with the database, even if in a transaction. This causes inconsistencies to show up and throw a respective exception immediately, and JDBC access code that participates in the same transaction will see the changes as the database is already aware of them then. But the drawbacks are:
In case of an existing Session, FLUSH_EAGER will turn the flush mode to AUTO for the scope of the current operation and issue a flush at the end, resetting the previous flush mode afterwards.
Never flush is a good strategy for read-only units of work. Hibernate will not track and look for changes in this case, avoiding any overhead of modification detection.
In case of an existing Session, FLUSH_NEVER will turn the flush mode to NEVER for the scope of the current operation, resetting the previous flush mode afterwards.
Apply the flush mode that's been specified for this accessor to the given Session.
null
if nonesession
- the current Hibernate SessionexistingTransaction
- if executing within an existing transactionCreate a close-suppressing proxy for the given Hibernate Session. The proxy also prepares returned Query and Criteria objects.
session
- the Hibernate Session to create a proxy forExecute the action specified by the given action object within a Session.
null
action
- callback object that specifies the Hibernate actionenforceNativeSession
- whether to enforce exposure of the native Hibernate Session to callback codeReturn if a flush should be forced after executing the callback code.
Prepare the given Criteria object, applying cache settings and/or a transaction timeout.
criteria
- the Criteria object to preparePrepare the given Query object, applying cache settings and/or a transaction timeout.
query
- the Query object to prepareSet the flush behavior to one of the constants in this class. Default is FLUSH_AUTO.