title: Springs Transaction Management - Understanding Spring Reference, Global/Local, Programmatic/Declarative - Two Questions
body: <p>Im working with the Spring Framework 3.0.5 and the Hibernate Framework and Im starting to use now Springs Transactionmanagement. I have some questions, just to understand how Springs Transactionmanagement works.</p>
  <p><strong>1)</strong></p>
  <p>I read this things in the Spring reference:</p>
  <blockquote>
  <p>a) Consistent programming model across different transaction APIs such as Java Transaction API (JTA), JDBC, Hibernate, Java Persistence API (JPA), and Java Data Objects (JDO).</p>
  <p>b) Spring resolves the disadvantages of global and local transactions. It enables application developers to use a consistent programming model in any environment. You write your code once, and it can benefit from different transaction management strategies in different environments.</p>
  <p>c) Gone are the days when the only alternative to using EJB CMT or JTA was to write code with local transactions such as those on JDBC connections, and face a hefty rework if you need that code to run within global, container-managed transactions. With the Spring Framework, only some of the bean definitions in your configuration file, rather than your code, need to change.</p>
  </blockquote>
  <p>From a) I understand that I can use those APIs with Spring <strong>without</strong> changing the code</p>
  <p>From b) I understand that I can use global or local transactions *<em>without</em> changing the code</p>
  <p>From c) I understand that while switching between different APIs and global/local transactions I <strong>need to change</strong> the code</p>
  <p>Now I wonder what is correct?</p>
  <p><strong>=&gt;</strong> Do I need to change the code? When switching between different APIs? When switching between local and global transactions? (Or does it maybe depend on prorgammatic and declarative transaction management?)</p>
  <p><strong>2)</strong></p>
  <p>I also got an additional question: I really wonder what <strong>the use</strong> of programmatic transaction management is? Everywhere I read that declarative transactionmanagement is recommended</p>
  <p>I read this in spring reference too:</p>
  <blockquote>
  <p>d) With programmatic transaction management, developers work with the Spring Framework transaction abstraction, which can run over any underlying transaction infrastructure. With the preferred declarative model, developers typically write little or no code related to transaction management, and hence do not depend on the Spring Framework transaction API, or any other transaction API.</p>
  </blockquote>
  <p>From d) I understand: with programmatic transaction management I can use any underlying transaction infrastructure... which means what? the different APIs mentioned above?</p>
  <p>and: with declarative I do not depend on any api</p>
  <p><strong>=&gt;</strong> isnt this the same? when I can use any underlying api, I do not depend on any api. I do not really understand this.</p>
  <p>where is the difference? I only know that the declarative transaction management is more lightweight, that I have not to start the transaction by my self and catch the exception and handle it and so on. But what is the use of programmatic transaction management then?</p>
  <p>Thank you for answering! :-)</p>