Hi all,
It's possible to set the FlushMode.COMMIT in HibernateSession using the "org.springframework.orm.hibernate4.support.OpenSe ssionInViewFilter" and "org.springframework.orm.hibernate4.HibernateTrans actionManager" as transactionManager?
With "org.springframework.orm.hibernate3.support.OpenSe ssionInViewFilter" you could set the FlushMode.COMMIT in this way:
but this solution it's not applicable in hibernate4 Filter. In this case it's always setted to MANUAL:
and then the HibernateTransactionManager set it to AUTO:
So apparently there's no way to change the FlushMode, the only solution seems to be to extend the HibernateTransactionManager to force the FlushMode.COMMIT, but IMHO this is not a great solution. There's some other way?
It's possible to set the FlushMode.COMMIT in HibernateSession using the "org.springframework.orm.hibernate4.support.OpenSe ssionInViewFilter" and "org.springframework.orm.hibernate4.HibernateTrans actionManager" as transactionManager?
With "org.springframework.orm.hibernate3.support.OpenSe ssionInViewFilter" you could set the FlushMode.COMMIT in this way:
Code:
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>COMMIT</param-value>
</init-param>
</filter>
Code:
protected Session openSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
try {
Session session = SessionFactoryUtils.openSession(sessionFactory);
session.setFlushMode(FlushMode.MANUAL);
return session;
}
catch (HibernateException ex) {
throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
}
}
Code:
if (!definition.isReadOnly() && !txObject.isNewSession()) {
// We need AUTO or COMMIT for a non-read-only transaction.
FlushMode flushMode = session.getFlushMode();
if (FlushMode.isManualFlushMode(session.getFlushMode())) {
session.setFlushMode(FlushMode.AUTO);
txObject.getSessionHolder().setPreviousFlushMode(flushMode);
}
}