JBOSS數據源的理解

http://blog.csdn.net/clinique/article/details/7482670


最近項目相關的JBOSS配置開始,留下點什麼


項目使用的是local-tx-datasource, 網上找了很多資料,都沒有明確說明local-tx-datasource和xa-datasource的區別,而且中文的資料太少,去JBOSS Community 查看了一圈找到了有價值的信息。

  1. local-tx-datasouce 能不能參與JTA事務

JBOSS Administration_Configuration_Guide上的解釋

<no-tx-datasource>

Does not take part in JTA transactions. The java.sql.Driveris used.

 

<local-tx-datasource>

Does not support two phase commit. The java.sql.Driveris used. Suitable for a single database or a non-XA-aware resource.

 

<xa-datasource>

Supports two phase commit. The javax.sql.XADataSourcedriver is used.

 

說的比較清楚,local-tx-datasource是可以作爲JTA事務參與者的, 只是不支持2PC協議(two-Phase-Commit Protocol)。

 

  1. 一個Application 能不能定義多個local-tx-datasource數據源,什麼時候用xa-datasource

 

在Forum上到的討論結果,JBOSS的開發人員認證了一下說法

You have to usexa-datasources in cases where onetransaction spans multiple datasources. Regardless of wheter Iuse a cluster or not.

 

 

For example amethod consuming a JMS message and manipulating a JPA Entity.

 

對這個說法的解釋就是,一個Application可以定義並使用很多個local-tx-datasource數據源,但是一個事務(Transaction)只能操作一個數據源。當你的事務需要同時處理不同的數據源的時候,必須定義爲xa-datasource,否則會出現org.jboss.util.NestedSQLException:Could not enlist in transaction on entering meta-aware object 的報錯。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章