我正在處理分佈式事務。我正在嘗試使用Atomikos作爲事務管理器來實現XA事務。我的一個問題是能夠從Websphere 6.1服務器上託管的DB2數據庫獲取「XADataSource」。 我使用JNDI查找,得到如下的數據源:如何從Websphere 6.1上託管的DB2數據庫獲取XADatasource
Context ctx=new InitialContext();
XADataSource ds = (XADataSource) ctx.lookup(dataSourceName);
然而,這種查找導致以下異常:
[3/21/12 12:08:47:551 EDT] 00000026 SystemErr R java.lang.ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource incompatible with javax.sql.XADataSource
[3/21/12 12:08:47:551 EDT] 00000026 SystemErr R at com.BusinessEntities.JndiConn.<init>(JndiConn.java:21)
[3/21/12 12:08:47:551 EDT] 00000026 SystemErr R at com.Servlet.InitialServlet.doGet(InitialServlet.java:41)
[3/21/12 12:08:47:551 EDT] 00000026 SystemErr R at com.Servlet.InitialServlet.doPost(InitialServlet.java:186)
[3/21/12 12:08:47:551 EDT] 00000026 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
[3/21/12 12:08:47:551 EDT] 00000026 SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
[3/21/12 12:08:47:551 EDT] 00000026 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1101)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:569)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3440)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:815)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1461)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:118)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
[3/21/12 12:08:47:566 EDT] 00000026 SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1473)
同樣工作正常,如果屬性「DS」是一個類型的數據源,而不是的XADataSource。但我想獲得XAConnections,因此需要XADataSource。我嘗試了很多搜索,但無法弄清楚如何避免這種拋出異常。 任何指針我應該做什麼不同?
我想讓自己不要使用TM,而不是使用另一個API,如Atomikos。因此需要XADataSource。 使用DataSource的UserTransaction工作正常,但我不想實現這個。 – Andy 2012-03-21 18:05:21
在這種情況下,我懷疑有一種方法可靠地使用容器管理的數據源,因爲RRA將假定它完全控制了事務交互。您最好使用DriverManager或直接與DB2類交互。 – 2012-03-21 20:27:32
@Andy:你究竟在做什麼(帽子還沒有被WebSphere的事務管理器提供)? – 2012-03-22 19:08:25