tags:

views:

121

answers:

3

Hi everyone, i'm developing an application running on WebLogic 10 and of course in java.

Ok, the thing is that i'm using oracle.jdbc.xa.client.OracleXADataSource to manage the transactions, and i'm also trying to set the OracleXADataSource object with InitialContext like this:

     InitialContext ctx = new InitialContext();
     OracleXADataSource oxds = new OracleXADataSource();
     oxds = (OracleXADataSource)ctx.lookup("cbs.db.CBSDataSrc");

But when i´m running the application this throws me this:

java.sql.SQLException: Error creando la conexion - weblogic.jdbc.common.internal.RmiDataSource cannot be cast to oracle.jdbc.xa.client.OracleXADataSource

 at cbs.rtc.daos.commons.DatabaseDAO.getXAPersConnection(DatabaseDAO.java:514)
 at cbs.rtc.daos.utils.UtilDAO.startTransaction(UtilDAO.java:95)
 at cbs.rtc.businessobjects.persona.PersonaJuridicaBussinessObject.crearClienteJuridico(PersonaJuridicaBussinessObject.java:366)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at cbs.rtc.businessobjects.AbstractBusinessObject.invoke(AbstractBusinessObject.java:61)
 at cbs.commons.business.BusinessInvoker.invokeTarget(BusinessInvoker.java:88)
 at cbs.services.AbstractService.invokeTarget(AbstractService.java:142)
 at cbs.services.AbstractService.invokeTarget(AbstractService.java:195)
 at cbs.services.persona.PersonaJuridicaServiceBean.crearClienteJuridico(PersonaJuridicaServiceBean.java:135)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        ...

Can anybody tell me why i'm getting that RmiDataSource can't be cast to OracleXADataSource ?

--EDIT-- And acording to this oracle sample that code should work, isn't it? http://www.oracle.com/technology/sample_code/tech/java/codesnippet/j2ee/jdbc/JDBC_in_J2EE.html

+1  A: 

The object returned is an RmiDataSource. OracleXADataSource is neither a subclass nor a superclass of RmiDataSource. The RmiDataSource talks directly or indirectly to the OracleXADataSource. It may or may not hold a a reference to the OracleXADataSource.

If you are using an XA data source, you should be using JTA to manage the transactions.

BillThor
I'm using JTA and I was setting the OracleXADataSource manually, but now is when i need to feed the database info to OracleXADataSource through InitialContext, what am I doing it wrong?
Wando
What database info do you need to feed to the context. It should already have the connection. Any connection setup should be done at the connection pool level. If you have queries to run, just use the datasource provided by the context and use JTA to commit or rollback.
BillThor
I'm using oracle to store my data, and the Driver Class for that connection is set to oracle.jdbc.xa.client.OracleXADataSource, but still throws the ClassCastException
Wando
Open up a support call for WebLogic. I have worked extensively with Oracle and WEbLogic, and not run into this kind of problem. Now that Oracle owns WEbLogic they should be able to work this out quickly.
BillThor
A: 

In addition to BillThor's answer,

this code should work for the XA datasource

cast RmiDataSource to javax.sql.DataSource

InitialContext ctx = new InitialContext();
     javax.sql.DataSource oxds = (DataSource)ctx.lookup("cbs.db.CBSDataSrc");
newtoallthis
well yes, that part is fine, but the OracleXADataSource object is used to get: XAConnection xaCon = oxds.getXAConnection(); and it's use with XAResource and Xid to handle transactions
Wando
A: 

You don't need to mess around with OracleXADataSource, XAConnection, XAResource nor Xid. All those classes are used internally by Weblogic's connection pool and transaction manager.

What you need is to get the datasource from JNDI like newtoallthis showed and the UserTransaction object as well to control the JTA transactions.

Ludovic Orban