Apr 15th, 2011, 03:01 PM
Hibernate with spring batch
Hi All !
I need to implement Spring Batch with Hibernate. My question is about transaction management.
1. Spring Batch writes meta data to job repository using jdbc. (Atleast that is my finding. Please let me know if this is not correct)
2. My ItemWriters would use hibernate to persist data that is read in ItemReaders.
3. I will need to ensure that Spring Batch and Hibernate are running in one single transaction.
It seems to me that I will need to define two transaction managers one for JDBC and another one for hibernate. How can I bring these two different transaction managers to participate in the same transaction ?
any pointers are much appreciated ?
Apr 18th, 2011, 01:01 AM
an HibernateTransactionManager should to the job, as long as the SessionFactory uses the same datasource as the JdbcTemplates.
Apr 22nd, 2011, 03:42 PM
in other words, if we make sure to use the same data source for the job-repository and hibernate configuration (session factory) then it should work. this way they both will share the same transaction manager and hence the scope...right?
Originally Posted by arno
by the way what would be the solution if our spring batch database is different and database for business domain objects is different?
Apr 25th, 2011, 09:24 AM
My guess would be then to use a container managed transaction API such as JTA.
Apr 26th, 2011, 07:33 AM
right, you would need JTA. You don't have to use a full-blown application server though, you can use standalone JTA transaction managers like Atomikos or Bitronix Transaction Manager.
Originally Posted by bleacherseat