|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.orm.hibernate.HibernateAccessor
public abstract class HibernateAccessor
Base class for HibernateTemplate
and HibernateInterceptor
,
defining common properties such as SessionFactory and flushing behavior.
Not intended to be used directly.
See HibernateTemplate
and HibernateInterceptor
.
HibernateTemplate
,
HibernateInterceptor
,
setFlushMode(int)
Field Summary | |
---|---|
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 Log |
logger
Logger available to subclasses |
Constructor Summary | |
---|---|
HibernateAccessor()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
protected net.sf.hibernate.FlushMode |
applyFlushMode(net.sf.hibernate.Session session,
boolean existingTransaction)
Apply the flush mode that's been specified for this accessor to the given Session. |
DataAccessException |
convertHibernateAccessException(net.sf.hibernate.HibernateException ex)
Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy. |
protected DataAccessException |
convertJdbcAccessException(net.sf.hibernate.JDBCException ex)
Convert the given JDBCException to an appropriate exception from the org.springframework.dao hierarchy. |
protected DataAccessException |
convertJdbcAccessException(SQLException ex)
Convert the given SQLException to an appropriate exception from the org.springframework.dao hierarchy. |
protected void |
flushIfNecessary(net.sf.hibernate.Session session,
boolean existingTransaction)
Flush the given Hibernate Session if necessary. |
net.sf.hibernate.Interceptor |
getEntityInterceptor()
Return the current Hibernate entity interceptor, or null if none. |
int |
getFlushMode()
Return if a flush should be forced after executing the callback code. |
SQLExceptionTranslator |
getJdbcExceptionTranslator()
Return the JDBC exception translator for this instance. |
net.sf.hibernate.SessionFactory |
getSessionFactory()
Return the Hibernate SessionFactory that should be used to create Hibernate Sessions. |
void |
setBeanFactory(BeanFactory beanFactory)
The bean factory just needs to be known for resolving entity interceptor bean names. |
void |
setEntityInterceptor(net.sf.hibernate.Interceptor entityInterceptor)
Set a Hibernate entity interceptor that allows to inspect and change property values before writing to and reading from the database. |
void |
setEntityInterceptorBeanName(String entityInterceptorBeanName)
Set the bean name of a Hibernate entity interceptor that allows to inspect and change property values before writing to and reading from the database. |
void |
setFlushMode(int flushMode)
Set the flush behavior to one of the constants in this class. |
void |
setFlushModeName(String constantName)
Set the flush behavior by the name of the respective constant in this class, e.g. |
void |
setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
Set the JDBC exception translator for this instance. |
void |
setSessionFactory(net.sf.hibernate.SessionFactory sessionFactory)
Set the Hibernate SessionFactory that should be used to create Hibernate Sessions. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int FLUSH_NEVER
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.
setFlushMode(int)
,
Constant Field Valuespublic static final int FLUSH_AUTO
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.
setFlushMode(int)
,
Constant Field Valuespublic static final int FLUSH_EAGER
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.
setFlushMode(int)
,
Constant Field Valuespublic static final int FLUSH_COMMIT
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.
setFlushMode(int)
,
Constant Field Valuesprotected final Log logger
Constructor Detail |
---|
public HibernateAccessor()
Method Detail |
---|
public void setSessionFactory(net.sf.hibernate.SessionFactory sessionFactory)
public net.sf.hibernate.SessionFactory getSessionFactory()
public void setEntityInterceptorBeanName(String entityInterceptorBeanName)
Requires the bean factory to be known, to be able to resolve the bean name to an interceptor instance on session creation. Typically used for prototype interceptors, i.e. a new interceptor instance per session.
Can also be used for shared interceptor instances, but it is recommended to set the interceptor reference directly in such a scenario.
entityInterceptorBeanName
- the name of the entity interceptor in
the bean factorysetBeanFactory(org.springframework.beans.factory.BeanFactory)
,
setEntityInterceptor(net.sf.hibernate.Interceptor)
public void setEntityInterceptor(net.sf.hibernate.Interceptor entityInterceptor)
Such an interceptor can either be set at the SessionFactory level, i.e. on LocalSessionFactoryBean, or at the Session level, i.e. on HibernateTemplate, HibernateInterceptor, and HibernateTransactionManager. It's preferable to set it on LocalSessionFactoryBean or HibernateTransactionManager to avoid repeated configuration and guarantee consistent behavior in transactions.
public net.sf.hibernate.Interceptor getEntityInterceptor() throws IllegalStateException, BeansException
null
if none.
Resolves an entity interceptor bean name via the bean factory,
if necessary.
IllegalStateException
- if bean name specified but no bean factory set
BeansException
- if bean name resolution via the bean factory failedsetEntityInterceptor(net.sf.hibernate.Interceptor)
,
setEntityInterceptorBeanName(java.lang.String)
,
setBeanFactory(org.springframework.beans.factory.BeanFactory)
public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
The default exception translator is either a SQLErrorCodeSQLExceptionTranslator if a DataSource is available, or a SQLStateSQLExceptionTranslator else.
jdbcExceptionTranslator
- the exception translatorSQLException
,
JDBCException
,
SessionFactoryUtils.newJdbcExceptionTranslator(net.sf.hibernate.SessionFactory)
,
SQLErrorCodeSQLExceptionTranslator
,
SQLStateSQLExceptionTranslator
public SQLExceptionTranslator getJdbcExceptionTranslator()
Creates a default SQLErrorCodeSQLExceptionTranslator or SQLStateSQLExceptionTranslator for the specified SessionFactory, if no exception translator explicitly specified.
public void setFlushModeName(String constantName)
constantName
- name of the constantsetFlushMode(int)
,
FLUSH_AUTO
public void setFlushMode(int flushMode)
setFlushModeName(java.lang.String)
,
FLUSH_AUTO
public int getFlushMode()
public void setBeanFactory(BeanFactory beanFactory)
setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (never null
).
The bean can immediately call methods on the factory.setEntityInterceptorBeanName(java.lang.String)
public void afterPropertiesSet()
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
protected net.sf.hibernate.FlushMode applyFlushMode(net.sf.hibernate.Session session, boolean existingTransaction)
session
- the current Hibernate SessionexistingTransaction
- if executing within an existing transaction
null
if nonesetFlushMode(int)
,
Session.setFlushMode(net.sf.hibernate.FlushMode)
protected void flushIfNecessary(net.sf.hibernate.Session session, boolean existingTransaction) throws net.sf.hibernate.HibernateException
session
- the current Hibernate SessionexistingTransaction
- if executing within an existing transaction
net.sf.hibernate.HibernateException
- in case of Hibernate flushing errorspublic DataAccessException convertHibernateAccessException(net.sf.hibernate.HibernateException ex)
org.springframework.dao
hierarchy. Will automatically detect
wrapped SQLExceptions and convert them accordingly.
The default implementation delegates to SessionFactoryUtils
and convertJdbcAccessException(net.sf.hibernate.JDBCException)
. Can be overridden in subclasses.
ex
- HibernateException that occured
convertJdbcAccessException(net.sf.hibernate.JDBCException)
,
SessionFactoryUtils.convertHibernateAccessException(net.sf.hibernate.HibernateException)
protected DataAccessException convertJdbcAccessException(net.sf.hibernate.JDBCException ex)
org.springframework.dao
hierarchy. Can be overridden in subclasses.
ex
- JDBCException that occured, wrapping a SQLException
setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)
protected DataAccessException convertJdbcAccessException(SQLException ex)
org.springframework.dao
hierarchy. Can be overridden in subclasses.
Note that a direct SQLException can just occur when callback code
performs direct JDBC access via Session.connection()
.
ex
- the SQLException
setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)
,
Session.connection()
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |