Please excuse if this or similar question has been asked before. I'm a novice to Spring. My question is how comes that transaction manager and JdbcTemplate are using the same DB connection. In all the documenation and books I could lay my hands on it' said that both beans (transaction manager and JDBC template) are given a data source. Let it be Apache Commons BasicDataSource. As far as I understand, both objects when instantiated will call method getConnection() of the data source and will be given different connections. After that JDBC template's update will be performed on one connection while transaction manager's commit on another. Definitely no transactional behavior will occur.
Where am I wrong?
Actually my program is a bit more complicated. It is multithreaded and it manages a connection pool. Initially each thread gets "connection" (actually JdbcTemplate object) and then uses it until termination. During its life it performs a series of database update "batches" which must be transactional. But attempt to use @Transactional annotation fails - if there are two insert operations in a batch and the second one fails, then the first one is not rolled back.
Both DataSourceTransactionManager and JdbcTemplate refer to the same BasicDataSource in beans.xml.
It's obvious that somewhere I'm terribly wrong in my understanding oа transaction management mecahism in Spring because other people use it happily. But where indeed?