title: TransactionTemplate and TransactionManager connection objects
body: <p>The following code in my DAO works perfectly fine.</p>
  
  <pre><code>public void insert(final Person person) {
      transactionTemplate.execute(new TransactionCallback&lt;Void&gt;() {
          public Void doInTransaction(TransactionStatus txStatus) {
              try {
                  getJdbcTemplate().execute("insert into person(username, password) values ('" + person.getUsername() + "','" + person.getPassword() + "')");
              } catch (RuntimeException e) {
                  txStatus.setRollbackOnly();
                  throw e;
              }
              return null;
          }
      });
  }
  </code></pre>
  
  <p>Following is my spring config.</p>
  
  <pre><code>&lt;bean id="derbyds" class="org.apache.commons.dbcp.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" /&gt;
      &lt;property name="username" value="app" /&gt;
      &lt;property name="password" value="app" /&gt;
      &lt;property name="url" value="jdbc:derby:mytempdb" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="persondaojdbc" class="com.napp.dao.impl.PersonDaoJdbcImpl"&gt;
      &lt;property name="dataSource" ref="derbyds" /&gt;
      &lt;property name="transactionTemplate"&gt;
          &lt;bean class="org.springframework.transaction.support.TransactionTemplate"&gt;
              &lt;property name="transactionManager" ref="transactionManager" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
      &lt;property name="dataSource" ref="derbyds"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>What i wanted to know is how does the   
          
          
          
          
      </p>
  
  <pre><code>&lt;bean id="persondaojdbc" class="com.napp.dao.impl.PersonDaoJdbcImpl"&gt;
      &lt;property name="dataSource" ref="derbyds" /&gt;
      &lt;property name="transactionTemplate"&gt;
          &lt;bean class="org.springframework.transaction.support.TransactionTemplate"&gt;
              &lt;property name="transactionManager" ref="transactionManager" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
      &lt;property name="dataSource" ref="derbyds"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now, its imperative that both the TransactionManager and the code (in my case jdbc template) operate on the same connection. I am assuming both of them are getting the Connection objects from the DataSource. DataSource pools connections and its a chance when you call getConnection multiple times, you will get different Connection obejcts. How does spring make sure that the TransactionManager and JdbcTemplate end up getting the same connection objects. My understanding is that, if that doesn't happen, rollbacks, or commits wont work, correct? Could someone throw more light on this.</p>