Oracle OCI driver problem

classic Classic list List threaded Threaded
5 messages Options
PMT
Reply | Threaded
Open this post in threaded view
|

Oracle OCI driver problem

PMT
I am using Tomcat 6 and Hibernate 3.3.1 with BTM 1.3.2. The database is Oracle XE. I am trying to convert an existing project which had been using hibernate.current_session_context_class="thread" to use "jta". My first step is to set allowLocationTransaction=true so that the existing code will run.

I followed the procedures for Tomcat integration and Hibernate integration.

When I used the "thin" driver, i.e. resource.ds.driverProperties.URL=jdbc:oracle:thin:@dbhost:1521:XE, there seemed to be no problem; I did not see any exceptions in the logs. (Unfortunately our IT wants us to use the OCI driver for operations reason.)

When I tried the "oci" driver, i.e. resource.ds.driverProperties.URL=jdbc:oracle:oci:@dbhost:1521:XE, I got the following exceptions. I checked the database monitor and connections were established.

The Oracle drivers are from the instant client package:
basic-10.2.0.4.0-linux-x86_64.zip and jdbc-10.2.0.4.0-linux-x86_64.zip

The resource.properties looks like this:
resource.ds.className=oracle.jdbc.xa.client.OracleXADataSource
resource.ds.uniqueName=jdbc/mydb
resource.ds.minPoolSize=10
resource.ds.maxPoolSize=40
resource.ds.driverProperties.user=mydb
resource.ds.driverProperties.password=mydb
resource.ds.driverProperties.URL=jdbc:oracle:oci:@dbhost:1521:XE
resource.ds.allowLocalTransactions=true

INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
Hibernate: select this_.PropertyId as PropertyId24_0_, this_.Timestamp as Timestamp24_0_, this_.Name as Name24_0_, this_.
Value as Value24_0_, this_.Created as Created24_0_, this_.CreatedBy as CreatedBy24_0_, this_.Updated as Updated24_0_, thi
s_.UpdatedBy as UpdatedBy24_0_ from Property this_ where this_.Name=?
org.hibernate.exception.GenericJDBCException: could not execute query
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
        at org.hibernate.loader.Loader.doList(Loader.java:2231)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
        at org.hibernate.loader.Loader.list(Loader.java:2120)
        at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
        at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
        at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:328)
        at com.xxxxxx.data.Property.getProperty(Property.java:175)
        at com.xxxxxx.ApplicationContext.init(ApplicationContext.java:290)
        at javax.servlet.GenericServlet.init(GenericServlet.java:212)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
        at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
        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 org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.sql.SQLException: error enlisting a JdbcConnectionHandle of a JdbcPooledConnection from datasource jdbc/m
lb in state ACCESSIBLE wrapping oracle.jdbc.xa.client.OracleXAConnection@558352d8 on oracle.jdbc.driver.LogicalConnection
@79038de7
        at bitronix.tm.resource.jdbc.JdbcConnectionHandle.enlistResource(JdbcConnectionHandle.java:61)
        at bitronix.tm.resource.jdbc.JdbcConnectionHandle.prepareStatement(JdbcConnectionHandle.java:200)
        at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
        at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
        at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
        at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1573)
        at org.hibernate.loader.Loader.doQuery(Loader.java:696)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
        at org.hibernate.loader.Loader.doList(Loader.java:2228)
        ... 35 more
Caused by: bitronix.tm.internal.BitronixSystemException: cannot enlist an XAResourceHolderState with uniqueName=jdbc/mlb
XAResource=oracle.jdbc.xa.client.OracleXAResource@5df4e571 with XID a Bitronix XID [746F6D6361742D62746D2D6E6F64653000000
11FA99935C300000000 : 746F6D6361742D62746D2D6E6F6465300000011FA99935E300000002], error=XAER_RMERR
        at bitronix.tm.BitronixTransaction.enlistResource(BitronixTransaction.java:83)
        at bitronix.tm.resource.common.TransactionContextHelper.enlist(TransactionContextHelper.java:267)
        at bitronix.tm.resource.common.TransactionContextHelper.enlistInCurrentTransaction(TransactionContextHelper.java:
49)
        at bitronix.tm.resource.jdbc.JdbcConnectionHandle.enlistResource(JdbcConnectionHandle.java:59)
        ... 43 more
Caused by: oracle.jdbc.xa.OracleXAException
        at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1120)
        at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:249)
        at bitronix.tm.internal.XAResourceHolderState.start(XAResourceHolderState.java:179)
        at bitronix.tm.internal.XAResourceManager.enlist(XAResourceManager.java:89)
        at bitronix.tm.BitronixTransaction.enlistResource(BitronixTransaction.java:76)
        ... 46 more
Reply | Threaded
Open this post in threaded view
|

Re: Oracle OCI driver problem

Ludovic Orban
Administrator
Hi,

First you need to know that if you enable allowLocationTransaction this means your application requires non-XA transactions. I've never tried myself but I've heard that with the Oracle OCI driver XA and non-XA transactions cannot be mixed.

Second the internal implementation of the OCI driver is completely different than for non-XA. You have to configure the OracleXADataSource in a different way (tnsEntry and nativeXA properties have to be configured) and you also have to make sure the native XA library is installed in the Oracle client.

See http://students.kiv.zcu.cz/doc/oracle/java.102/b14355/xadistra.htm#BGBGBEEF for more details. You might need Oracle's support on this.
PMT
Reply | Threaded
Open this post in threaded view
|

Re: Oracle OCI driver problem

PMT
Hi,

Thanks for the quick response. I am just starting a trial of adding JTA to an existing application. So my first step was to test the set up and configuration without changing existing code. That why I enabled allowLocationTransaction.

It does seem OCI driver is more complicated. So before I get in too deep, could I get your opinion on the following? The application has only one data source. What would be the advantage of using JTA transaction (hibernate.current_session_context_class=jta) as compared to JDBC transaction (hibernate.current_session_context_class=thread)? i.e.
This :-

try {
     tx = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");
     tx.begin();
     session = HibernateUtil.getSessionFactory().getCurrentSession();
             ...
     utx.commit();
} catch (Exception e) {
      utx.rollback();
}

compared to this:-

try {
    session = HibernateUtil.getSessionFactory().getCurrentSession();
    tx = session.beginTransaction();
           ...
    tx.commit();
} catch (Exception e) {
     tx.rollback();
}

Thanks.

Ludovic Orban wrote
Hi,

First you need to know that if you enable allowLocationTransaction this means your application requires non-XA transactions. I've never tried myself but I've heard that with the Oracle OCI driver XA and non-XA transactions cannot be mixed.

Second the internal implementation of the OCI driver is completely different than for non-XA. You have to configure the OracleXADataSource in a different way (tnsEntry and nativeXA properties have to be configured) and you also have to make sure the native XA library is installed in the Oracle client.

See http://students.kiv.zcu.cz/doc/oracle/java.102/b14355/xadistra.htm#BGBGBEEF for more details. You might need Oracle's support on this.
Reply | Threaded
Open this post in threaded view
|

Re: Oracle OCI driver problem

Ludovic Orban
Administrator
Did you read this: http://docs.codehaus.org/display/BTM/JtaBestPractices ?

In short, using JTA has those advantages:

 - Decoupling TX management from data management (one class for the TX, another one for the SQL). Hibernate already gives you that but JTA is a standard API so your transaction management code isn't tied to Hibernate.
 
 - 2PC can be added when needed with no change to your architecture.

 - you can prevent resource hogs with timeouts.

 - You can guarantee that all your data access code is running in transactions.

PMT
Reply | Threaded
Open this post in threaded view
|

Re: Oracle OCI driver problem

PMT
Thanks for the advice. I think I'll either use BTM JTA with Oracle thin client if that is agreeable to our IT or use Hibernate with JDBC transaction. I'll try the OCI driver again when I have time. It seems some needed XA libraries can only be found in the full Oracle client package and not the instant client.

Thanks again.

Ludovic Orban wrote
Did you read this: http://docs.codehaus.org/display/BTM/JtaBestPractices ?

In short, using JTA has those advantages:

 - Decoupling TX management from data management (one class for the TX, another one for the SQL). Hibernate already gives you that but JTA is a standard API so your transaction management code isn't tied to Hibernate.
 
 - 2PC can be added when needed with no change to your architecture.

 - you can prevent resource hogs with timeouts.

 - You can guarantee that all your data access code is running in transactions.