| Author |
getting org.jboss.resource.adapter.jdbc.WrapperDataSource cannot be cast to javax.sql.XADataSource
|
Suresh krishnas
Greenhorn
Joined: Sep 19, 2009
Posts: 4
|
|
Hello All,
I have configured XA Datasource in JBOSS AS and the database is DB2. When i try to lookup the datasource from my application i get the below error.
10:43:45,005 ERROR [STDERR] java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrapperDataSource cannot be cast to javax.sql.XADataSource
Appritiate your help on this issue, below is my db2-xa-ds.xml entry.
When i try to get Normal Connection object it works but when i look for XAConnection object its failing, could you please suggest any solution on this.
Thanks
suresh
|
 |
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8141
|
|
|
Please post the entire exception stacktrace and the code where you are doing the cast.
|
[My Blog] [JavaRanch Journal]
|
 |
Suresh krishnas
Greenhorn
Joined: Sep 19, 2009
Posts: 4
|
|
Hi,
Thanks for the response. below is the full error stack
09:50:31,808 INFO [STDOUT] Returned Class from lookup [class org.jboss.resource.adapter.jdbc.WrapperDataSource]!!!
09:50:31,808 ERROR [STDERR] java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrapperDataSource cannot be cast to javax.sql.XADataSource
09:50:31,808 ERROR [STDERR] at com.common.datasourcehelper.DataSourceHelper.getDataSource(DataSourceHelper.java:66)
09:50:31,808 ERROR [STDERR] at com.common.datasourcehelper.DataSourceHelper.getLiveDataSource(DataSourceHelper.java:83)
09:50:31,808 ERROR [STDERR] at ava:261)
09:50:31,824 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
09:50:31,824 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
09:50:31,824 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
09:50:31,824 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
09:50:31,824 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
09:50:31,824 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
09:50:31,824 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
09:50:31,824 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
09:50:31,824 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
09:50:31,824 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
09:50:31,824 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
09:50:31,824 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
09:50:31,824 ERROR [STDERR] at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
09:50:31,824 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
09:50:31,824 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
09:50:31,824 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
09:50:31,824 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
09:50:31,824 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
09:50:31,824 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
09:50:31,824 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)
09:50:31,824 INFO [CommandExecuter] Command: com.servercommon.microflow.commands.ExecuteMicroflowCommand completed successfully
the code is
dataSource = (XADataSource)ctx.lookup(jndiName);
|
 |
Jeremy Whiting
Greenhorn
Joined: Mar 05, 2008
Posts: 10
|
|
Hi Suresh,
Looking at your code it looks like you are trying to obtain an XADataSource directly and unnecessarily.
When performing a JNDI lookup try casting the returned object to the javax.sql.DataSource interface. Then use the DataSource to obtain a reference to java.sql.Connection. This is still true even though you have configured the datasource connection configuration in db2-xa-ds.xml with an XA compliant object. Your application code does not and should not know the underlying (XA) implementation class.
Why does it not need to care ?
Behind the scenes JBoss is intercepting the call to javax.sql.DataSource.getConnection() and returning to the application a wrapped Connection object. The JBoss wrapper in this particular case is WrapperDataSource. First line of the stack trace.
The wrapping of the Connection object allows JBoss to pool the physical Connection objects. When an application requests a Connection the JBoss connection pool allocates a logical Connetion for the duration an application needs it.
Additionally, because the Connection object is wrapped the call to Connetion.commit() or Connection.abort() is also intercepted. This frees you from having to worry about controlling the distributed transaction interaction.
Try the suggestion above and let us know how you progress.
Regards,
Jeremy
SCJP, SCWCD
|
 |
Suresh krishnas
Greenhorn
Joined: Sep 19, 2009
Posts: 4
|
|
Hi Jeremy,
Thanks a lot for reply and sorry for the delay.
I know the underlying connection is XA, The requirement is i need to do a Distributed Transaction between multiple databases. I am not using any UserTransaction/EJB or any thing, just plain jdbc. so i need to get XADatasource inorder to utilize XAResource to make sure all operations are part of a single transaction. which is not happening as i am unable to retrive an XADatasource Object. Could you please suggest on the same.
Thanks
Suresh
|
 |
Jeremy Whiting
Greenhorn
Joined: Mar 05, 2008
Posts: 10
|
|
Hi Suresh,
You do not need to get the XADatasource.
If you get the UserTransaction object from the JNDI tree JBoss application server will make the 2x datasource work all in 1 transaction. This is one of the services provided by JBoss AS. You the developer do not have to get XADatasource. Instead the transaction manager inside JBoss take responsibility for managing the distributed transaction.
I recommend you seriously consider using the JTA specification UserTransaction interface provided by JBoss in JNDI. Doing this will delegate transaction management to the application server.
If you really want to understand distributed transactions then I recommend this book.
"Java Transaction Processing: Design and Implementation" (Paperback)
by Mark Little (Author), Jon Maron (Author), Greg Pavlik (Author)
and the JBoss JTA Developers guide for AS 4.2.3, look at the JDBC example section
http://www.jboss.org/jbosstm/docs/4.2.3/manuals/html/jta/ProgrammersGuide.html
Is this commercial work or certification you are doing ?
Kind regards,
Jeremy
|
 |
Suresh krishnas
Greenhorn
Joined: Sep 19, 2009
Posts: 4
|
|
Hello Jeremy,
Thanks a lot for the suggestion i am able to work with 'UserTransaction', We will go ahead with the development, if in case i get an issue i will get to you.. Thanks a lot once again.
Thanks
Suresh
|
 |
 |
|
|
subject: getting org.jboss.resource.adapter.jdbc.WrapperDataSource cannot be cast to javax.sql.XADataSource
|
|
|