You can configure each javax.sql.DataSource
object to enable auto-commit if that does the job, or disable auto-commit and write the transaction logic programatically.
Both the java.sql.Connection
and the javax.sql.DataSource
class have methods for enable/disable auto-commit.
Regarding dependency injection and Spring, you can still inject a datasource object into your repository. If you also let each repository extend the org.springframework.jdbc.core.support.JdbcDaoSupport
class, then you have a JdbcTemplate object available for you with the derived getJdbcTemplate()
method.
You can also let Spring handle the transaction handling for you. Without a XA transaction manager, you need one transaction manager for each datasource. With many transaction managers, declarative transaction support with the @Transactional
annotation is impossible. You can however, inject the transaction manager into your service class. This is described in the reference documentation here.