title: Difference between physical and logical transactions in spring
body: <p>In this spring document 
  <strong><a href="http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/transaction.html" rel="noreferrer">http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/transaction.html</a></strong> .It talks about physical and logical transactions.I have written a very simple program to understand it</p>
  
  <h2><code>TransactionObject.java</code></h2>
  
  <pre><code>class TransactionObject {
  
      private static Connection conn;
  
      TransactionObject() {
          try {
              conn = DriverManager.getConnection("DB_URL", "USER", "PASS");
          } catch (SQLException e) {}
      }
  
      void rollBack() {
          try {
              conn.rollback();
          } catch (SQLException e) { }
      }
  
      void Commit() {
          try {
              conn.commit();
          } catch (SQLException e) { }
      }
  }
  </code></pre>
  
  <h2><code>ClassMethodUnderTransactionObject.java</code></h2>
  
  <pre><code>public class ClassMethodUnderTransactionObject {
      // start fresh TransactionObject
      TransactionObject  logical= new TransactionObject();
  
      M2(); // call M2 use same logical object
      M3(); // call M3 use same logical object
      // For M2 and M3 it is logical transaction because both using same transaction object
  
      if(error){
          logical.rollBack();  
      } else {
          logical.Commit(); 
      }
  
      // create another instance of TransactionObject
      TransactionObject  physical=new TransactionObject();
  
      M4(); // call M4 use different TransactionObject object
      if(error){
          physical.rollBack();  
      } else {
          physical.Commit(); 
      }
  </code></pre>
  
  <p>So M4 uses physical transaction in respect to  M2 and  M3 becuase M4 uses different trasnactionObject</p>
  
  <p>Is that the way we should understand ?Is there more to understand.Please help me to understand it.</p>