|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.orm.hibernate.HibernateAccessor
Base class for HibernateTemplate and HibernateInterceptor, defining common properties like 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_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 org.apache.commons.logging.Log |
logger
|
Constructor Summary | |
HibernateAccessor()
|
Method Summary | |
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
DataAccessException |
convertHibernateAccessException(net.sf.hibernate.HibernateException ex)
Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy. |
protected DataAccessException |
convertJdbcAccessException(java.sql.SQLException ex)
Convert the given SQLException to an appropriate exception from the org.springframework.dao hierarchy. |
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 |
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 |
setFlushMode(int flushMode)
Set the flush behavior to one of the constants in this class. |
void |
setFlushModeName(java.lang.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
setFlushMode(int)
,
Constant Field Valuespublic static final int FLUSH_AUTO
setFlushMode(int)
,
Constant Field Valuespublic static final int FLUSH_EAGER
setFlushMode(int)
,
Constant Field Valuesprotected final org.apache.commons.logging.Log logger
Constructor Detail |
public HibernateAccessor()
Method Detail |
public void setSessionFactory(net.sf.hibernate.SessionFactory sessionFactory)
public net.sf.hibernate.SessionFactory getSessionFactory()
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.
LocalSessionFactoryBean.setEntityInterceptor(net.sf.hibernate.Interceptor)
,
HibernateTransactionManager.setEntityInterceptor(net.sf.hibernate.Interceptor)
public net.sf.hibernate.Interceptor getEntityInterceptor()
public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
The default exception translator evaluates the exception's SQLState.
jdbcExceptionTranslator
- exception translatorSQLStateSQLExceptionTranslator
,
SQLErrorCodeSQLExceptionTranslator
public SQLExceptionTranslator getJdbcExceptionTranslator()
public void setFlushModeName(java.lang.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 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
public 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)
The default implementation delegates to SessionFactoryUtils and convertJdbcAccessException. Can be overridden in subclasses.
ex
- HibernateException that occured
convertJdbcAccessException(java.sql.SQLException)
,
SessionFactoryUtils.convertHibernateAccessException(net.sf.hibernate.HibernateException)
protected DataAccessException convertJdbcAccessException(java.sql.SQLException ex)
Note that SQLException can just occur here when callback code performs direct JDBC access via Session.connection().
ex
- SQLException that occured
setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |