Atomikos Forum

Class Cast Exception on using AtomikosDataSourceBean

I am trying to perform a jndi lookup for DB2 database hosted on Websphere 6.1 in the following manner:

Context ctx=new InitialContext();
AtomikosDataSourceBean ds = (AtomikosDataSourceBean) ctx.lookup(dataSourceName);

However, encontered the following Exception:

java.lang.ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource incompatible with com.atomikos.jdbc.AtomikosDataSourceBean


Does that mean i cannot use the AtomikosDataSourceBean for jndi lookup on websphere? What is the correct method then?
Anirudh Rathi Send private email
Monday, March 26, 2012
 
 
You need to construct a "new" AtomikosBean instance and set the JNDI datasource to this bean - see docs how to use the bean.
You cannot cast them.
Torsten Krah Send private email
Tuesday, March 27, 2012
 
 
@Torsten:

This is the code i am using now to do the jndi lookup.

Context ctx = new InitialContext();
ds = new AtomikosDataSourceBean();
ds.setXaDataSource((XADataSource) ctx.lookup("jdbc/dataSource1"));

This causes the following exception:
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R java.lang.ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource incompatible with javax.sql.XADataSource
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.BusinessEntities.JndiConn.<init>(JndiConn.java:26)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.Servlet.InitialServlet.init(InitialServlet.java:42)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at javax.servlet.GenericServlet.init(GenericServlet.java:256)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:218)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:319)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:412)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3440)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:815)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1461)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:118)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:267)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
[3/27/12 11:44:13:292 EDT] 0000004d SystemErr    R     at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1473)

which as the 1st line says, is due to WSJdbcDataSource (Websphere's datasource) not being able to be cast to XADatasource.

How else should I use the AtomikosDataSourceBean class ??

P.S: this isnt a spring project.I am not using EJB.
Anirudh Rathi Send private email
Tuesday, March 27, 2012
 
 
I you want XA, you must provide a XADataSource if you want to get it from JNDI. Reconfigure your J2EE Container to provide a XADataSource.
Torsten Krah Send private email
Wednesday, March 28, 2012
 
 
@Torsten:

I have tried to search a lot to get an XADataSource from WebSphere. Can you provide a way to reconfigure my J2EE Container(WAS in my case) to provide a XADataSource?
Anirudh Rathi Send private email
Wednesday, April 25, 2012
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics