When using hibernate 3, the following code works:
<bean id="ivsHibernateWriter"
class="org.springframework.batch.item.database.HibernateItemWriter">
<property name="hibernateTemplate" ref="hibernateTemplate"/>
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean class="org.springframework.orm.hibernate3.HibernateTemplate" id="hibernateTemplate" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
After upgrading to hibernate 4, my test failes with this exception:
org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder
I thought of changing the hibernateTemplate bean to be inline with hibernate 4, like so:
<bean class="org.springframework.orm.hibernate4.HibernateTemplate" id="hibernateTemplate" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
However, this class does not exist.
How should we work with Hibernate4 and spring Batch?
This is not possible for now, since Spring Batch does not support hibernate4 .
You may see the Jira issue about this https://jira.springsource.org/browse/BATCH-1904
I kindly suggest working with JdbcItemWriters in case you do not have a strict business requirement; imho, hibernate and jpa are poorly supported in spring batch (and I understand why).