In order to work around Hibernate bug HHH-2763, I'm trying to update my app from Hibernate 3 to Hibernate 4. It seemed to have gone smoothly until I realized that while my application can read data, it never seems to do inserts or updates. I turned on SQL logging: under Hibernate 3, there are inserts and updates. Under Hibernate 4, there are no inserts and updates.
We were doing explicit flushes in Hibernate 3 by overriding the OpenSessionInViewFilter class' closeSession
method as follows:
public void closeSession(Session session, SessionFactory sessionFactory) {
session.flush();
super.closeSession(session, sessionFactory);
}
But in Hibernate 4, this is no longer an option because that method no longer exists.
My Hibernate 4 configuration for the Session Factory and Transaction Manager follows:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.default_schema">${oracle.default_schema}</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.show_sql">${hibernate.showSql}</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list> . . . </list>
</property>
<property name="annotatedClasses">
<list> . . . </list>
</property>
</bean>
<!-- Configure transaction management, enabling @Transactional annotations -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
<property name="nestedTransactionAllowed" value="true" />
</bean>
(Edit) And here's the configuration of the OpenSessionInViewFilter
:
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
My guess is that it's not flushing and committing. But why?