Announcement Announcement Module
Collapse
No announcement yet.
Two Data Sources and Transaction Managers against same database Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Two Data Sources and Transaction Managers against same database

    I am working on a grails application that has data source defined in DataSource.groovy file and has default grails Hibernate Transaction Manager. HibernateDaoSupport is being used to persist data in database with session factory from grails application context.

    Now i have added spring batch to this application to handle batch jobs. For some reason i can not use pre defined transaction manager or data source. I have defined a separate data source and transaction manager (DatasourceTransactionManager) for spring batch job and separate context for spring batch beans.

    Now i have question if it is a valid practice to do? What can be cons of this approach?

    Thanks,

  • #2
    It is a valid approach. Given that you probably won't be doing everything with Hibernate via batch (at the very least, the updates to the JobRepository use straight JDBC), using the DataSourceTransactionManager makes sense.

    With regards to cons...the biggest one I can think of is that you won't have the updates via GORM and the updates via batch done within the same transaction. An alternative approach would be to use a separate DataSource for batch and use an XA transaction manager for both data sources.

    Comment

    Working...
    X