title: When to Use XA Datasource and Non XA Datasource
body: <p>I'm trying to understand the use of Java XA Datasource.
  But I can't still figure when to use it, and when not to use it.</p>
  
  <p>I read that XA Datasource used when we use two databases.
  But I'm not sure what is the meaning of two database.</p>
  
  <p>For example:</p>
  
  <p>I had two layer of classes (Service and DAO)</p>
  
  <p>A method in service layer annotated as a transaction, invoke two methods in DAO.</p>
  
  <p>Each method in DAO open new connection to database and close it in the end of the method.</p>
  
  <p>If I use one instance of database, and each method in DAO write to different table, do I have to use XA Datasource? since transaction occured in service layer but only in one instance database</p>