|
||||||||||
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 like 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_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
|
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(HibernateException ex)
Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy. |
protected DataAccessException |
convertJdbcAccessException(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(Session session,
boolean existingTransaction)
Flush the given Hibernate Session if necessary. |
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. |
SessionFactory |
getSessionFactory()
Return the Hibernate SessionFactory that should be used to create Hibernate Sessions. |
void |
setEntityInterceptor(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(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(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 Log logger
Constructor Detail |
---|
public HibernateAccessor()
Method Detail |
---|
public void setSessionFactory(SessionFactory sessionFactory)
public SessionFactory getSessionFactory()
public void setEntityInterceptor(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 Interceptor getEntityInterceptor()
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 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 void flushIfNecessary(Session session, boolean existingTransaction) throws HibernateException
session
- the current Hibernate SessionexistingTransaction
- if executing within an existing transaction
HibernateException
- in case of Hibernate flushing errorspublic DataAccessException convertHibernateAccessException(HibernateException ex)
org.springframework.dao
hierarchy. Will automatically detect
wrapped SQLExceptions and convert them accordingly.
The default implementation delegates to SessionFactoryUtils and convertJdbcAccessException. Can be overridden in subclasses.
ex
- HibernateException that occured
convertJdbcAccessException(net.sf.hibernate.JDBCException)
,
SessionFactoryUtils.convertHibernateAccessException(net.sf.hibernate.HibernateException)
protected DataAccessException convertJdbcAccessException(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()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |