ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedPreparedStatementJDK6 cannot be cast to OraclePreparedStatement - oracle

I'm working to migrate an application from Oracle Application Server to JBoss EAP 6.1. I have most things working but I am getting one error that I haven't been able to figure out:
13:27:29,743 ERROR [com.myproj.db.dao.myDao] (Thread-164) Get Prepared Statement:
java.lang.ClassCastException:
org.jboss.jca.adapters.jdbc.jdk6.WrappedPreparedStatementJDK6 cannot be cast
to oracle.jdbc.internal.OraclePreparedStatement
I have Oracle set up as a module in JBoss for connection pooling using ojdbc6.jar (and it works for other parts of the application), but for the one part of the application that uses an OraclePreparedStatement, it gets the error.
I did make certain that there is no ojdbc6.jar file in the WAR file. The only one in JBoss seems to be inside of the module.
I did try changing the OraclePreparedStatement class to oracle.jdbc.OraclePreparedStatement, but the results are the same.
I did try running with TRACE on for logging to see where classes were loading from. OraclePreparedStatement was loaded from the module with the exception of this line:
4:31:40,583 TRACE [org.jboss.modules] (Thread-84) Finding class
oracle.jdbc.OraclePreparedStatement from Module "deployment.myProj.war:main" from
Service Module Loader
Here's a link to an excerpt of the log - basically just the lines related to OraclePreparedStatement.
I have confirmed that there is no ojdbc6.jar (or any Oracle related jars) in the WAR file, and there is no OraclePreparedStatement class inside of the WAR file either.
I do have the module listed as a dependency in my JBoss deployment structure xml file.
Anyone have any ideas?

From looking at the javadoc I would guess that org.jboss.jca.adapters.jdbc.jdk6.WrappedPreparedStatementJDK6 is wrapping the underlying Oracle JDBC driver.
org.jboss.jca.adapters.jdbc.jdk6.WrappedPreparedStatementJDK6 has a method to get the underlying statement. Perhaps you should try something like the following:
WrappedPreparedStatementJDK6 statement = ...
OraclePreparedStatement oracleStatement = (OraclePreparedStatement)statement.getUnderlyingStatement();

Related

WebSphere Liberty and Eclipselink SDO

I am porting an old IBM Process Server application to IBM WebSphere Liberty. It contains a lot of code based on Service Data Objects (SDO). I have some good working code, running as standalone Java, using JDK8. I am using eclipselink 2.7.7, specifically 2 jar files;
eclipselink.jar
commonj.sdo_2.1.1v20111051852.jar
I have built this code into a Servlet to handle SOAP requests, and packaged it, along with other code, into an EAR file, which I deployed under IBM WebSphere Liberty 20. It doesn't work. There seems to be a clash with the Liberty version of EclipseLink.
If I deploy the code as a WAR file, and add a classloader of "PARENT_LAST", the code works fine.
However, if I try to deploy the code in an EAR file, and set a classloader of "PARENT_LAST" for the ear file, I get this error;
[ERROR ] CWWKZ0106E: Could not start web application S21.
[ERROR ] CWWKZ0002E: An exception occurred while starting the application S21. The exception message was: com.ibm.ws.container.service.state.StateChangeException: java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "org.eclipse.persistence.jpa.PersistenceProvider.getProviderUtil()Ljavax/persistence/spi/ProviderUtil;" the class loader (instance of com/ibm/ws/classloading/internal/ParentLastClassLoader) of the current class, org/eclipse/persistence/jpa/PersistenceProvider, and the class loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) for interface javax/persistence/spi/PersistenceProvider have different Class objects for the type javax/persistence/spi/ProviderUtil used in the signature
Does anyone know whether I can replace the IBM Liberty implementation of EclipseLink with my version 2.7.7 version?
My application also uses JPA, which is working fine under Liberty, so I don't want to break that.
Any help / guidance appreciated... it's been a very long saturday.
PS:
I tried running the java code using only the SDO library (commonj.sdo_2.1.1v20111051852.jar), and relying on the WebSphere Liberty runtime jars to provide Eclipselink functionality, and I got the following errors, which is why I then moved to adding the "matching pair" of Eclipselink / SDO jars mentioned above;
Caught Exception : org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getSystemPropertyBoolean(Ljava/lang/String;Z)Z
java.lang.NoSuchMethodError: org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getSystemPropertyBoolean(Ljava/lang/String;Z)Z
at org.eclipse.persistence.sdo.helper.SDOHelperContext.<init>(SDOHelperContext.java:93)
at org.eclipse.persistence.sdo.helper.SDOHelperContext$DefaultHelperContextResolver.getHelperContext(SDOHelperContext.java:1432)
at org.eclipse.persistence.sdo.helper.SDOHelperContext.getHelperContext(SDOHelperContext.java:492)
at org.eclipse.persistence.sdo.helper.SDOHelperContext.getHelperContext(SDOHelperContext.java:471)
at org.eclipse.persistence.sdo.helper.SDOHelperContext.getHelperContext(SDOHelperContext.java:456)
at org.eclipse.persistence.sdo.helper.delegates.SDOXMLHelperDelegator.getXMLHelperDelegate(SDOXMLHelperDelegator.java:178)
at org.eclipse.persistence.sdo.helper.delegates.SDOXMLHelperDelegator.load(SDOXMLHelperDelegator.java:78)
at com.ebs.solas2021.port.adapter.ui.SOAPRequestHandler.main(SOAPRequestHandler.java:237)
It's amazing what you find whgen you re-read the documentation in the cold light of a new day. It turns out that it's possible to install a JPA 2.2 Container on Liberty, while supplying one's own implementation of EclipseLink. Works like a charm.
Documented here: https://openliberty.io/blog/2018/06/29/full_java_ee_8_liberty_18002.html

RazorSQL causes HSQLDB to throw org.hsqldb.HsqlException: Client driver version greater than '2.1.0.0' is required. HSQLDB server version is '2.3.4'

I am not able to connect to my HSQLDB database from RazorSQL. I am only having this issue when I am running in Server mode and when I am attempting to connect from RazorSQL.
Using the same URL from Eclipse Data Source Explorer, and from the application itself (which is a Hibernate 5.2.7 application), I am able to successfully connect to my database at the URL "jdbc:hsqldb:hsql://localhost/SudokuHibernate". Since I am running it in Server mode, I am able to connect concurrently.
(Note: I don't have to have multiple concurrent connections, but it make debugging easier). The database is being run in Server mode from the command line via ...
java -cp ../libs/hsqldb-2.3.4/hsqldb/lib/hsqldb.jar org.hsqldb.server.Server --database.0 file:/Users/arick/src/databases/SudokuHibernate --dbname.0 SudokuHibernate
When attempting to connect from RazorSQL, the database console shows the error message. "org.hsqldb.HsqlException: Client driver version greater than '2.1.0.0' is required. The HSQLDB server version is '2.3.4'".
Note: This is a different question then a similar StackOverflow question, as all of my own configuration files are explicitly referencing the same JDBC driver, from the same jar file. However, as pointed out by Fred T, the reference to '2.1.0.0', by HSQLDB, is somewhat misleading. It is really just saying that the client and the server have two different versions of the JDBC driver.
At the same time that the database is throwing a mismatched version error, RazorSQL displays a dialog box with the error message:
ERROR: An error occurred while trying to make a connection to the database:
JDBC URL: jdbc:hsqldb:hsql://localhost/SudokuHibernate
connection exception: connection failure: java.io.EOFException
Below is my RazorSQL connection profile.
RazorSQL Profile
Driver Location: /Users/arick/src/libs/hsqldb-2.3.4/hsqldb/lib/hsqldb.jar
JDBC URL: jdbc:hsqldb:hsql://localhost/SudokuHibernate
As was inferred by Mark Rotteveel, the answer is similar to a related question about how to get Eclipse and Maven to talk to a HSQLDB server that is running in standalone server mode.
In that case, Fred Toussi, the lead on the HSQLDB project, pointed out the answer was to modify the configuration file, that is used in Eclipse and Maven, to pull in the appropriate version of the HSQLDB JDBC jar file, and also to make sure the jar file didn't appear anywhere else on the classpath. Maven uses a pom.xml file for configuration; so what was needed was make sure that the correct version of the HSQLDB was defined in the project's pom.xml file.
In my situation, the RazorSQL product that I was using, just happens to use HSQLDB as the embedded database for itself. If I had been using any other Java database, I may not have had this problem. But, since the RazorSQL product had already loaded its own version of the HSQLDB jar file, it didn't matter what I specified in my configuration for the database connection. It wasn't going to work.
No matter how I changed my driver profile, or my connection profile, the only version of the HSQLDB jar file that was going to get loaded, was the original jar file, that was already in use by RazorSQL, and that came with RazorSQL. (Note: This is true, unless RazorSQL gets fancy, and it decides to use a different classloader, and some of the other tricks that are commonly used by Java applications servers to solve these problems).
As per suggestion from Dan Richardson, from RazorSQL, the actual answer was not by modifying my configurations, but by changing the contents of the RazorSQL distribution itself. I needed to replace the jar file that is used by the RazorSQL application. This jar file is in Mac application folder for RazorSQL. This location is typically at /Applications/RazorSQL.app/Contents/Java/drivers/hsqldb.
(Note: If you are not familiar with how to open a Mac app folder, you just right-click on the RazorSQL folder name in the /Applications directory and use the "Show Package Contents" menu option). In my case, I renamed the original hsqldb.jar file to be hsqldb_2.3.2.jar file, and then I copied in the last distribution of the hsqldb.jar.

gradle jettyrun oracle no suitable driver found

This is a kind of driving me nuts, I found some similar questions here on SO but I can't get it to work.
I have a multi project spring (web) project. It starts fine, but as soon as I want to query the db I get a
Nested in org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException:
Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver' for connect URL 'jdbc:oracle:thin//server:1521:XE':
I tried many things: I made sure the ojdbc.jar is inside my project (not part of maven repo so I loaded it with gradle like
compile files('lib/websphere_apis.jar','lib/ojdbc14.jar')
in my sub (not web) or in my web project.
Which gets the jars inside war when I generate them with with gradle war
I tried adding the jars to the jettyRun configuration with
jettyRun {
additionalRuntimeJars = files('lib/ojdbc14.jar')
}
I'm a bit in doubt whether the files stmt is correct but still it doesn't work.
I also found on SO that I should put
providedRuntime files("$projectDir/../lib/ojdbc14.jar")
inside my webapp as a standard dependency but that still doesn't work for me. I have used postgres driver jars before which I could just include as a dependency.
With JDBC .jar files, if you are not careful about where you load the .jar on the classpath, you might get an error like what you are seeing. If you want to be sure, pass the .jar on the classpath as an argument to the main JVM that is calling the program. The reason is that you need to make sure the .jar class files are loaded in the "default JVM classloader". If you try to load JDBC .jars dynamically through other means ( perhaps even as OSGI) , or dynamically loaded by custom classloader like Tomcat has, then you could get class loader issues.

Playframework 2 with Oracle throws InvocationException

When running the "java/computer-database" sample with an Oracle db instead of the H2 one, Computer.find.byId() results in "com.sun.jdi.InvocationException occurred invoking method.".
The Application.list() is showing the correct data.
I have this in my application.conf:
db.default.url="jdbc:oracle:thin:#xx.xx.xx.xx:1521:somename"
db.default.driver=oracle.jdbc.driver.OracleDriver
In my lib directory I have
ojdbc6.jar
orai18n.jar
When searching for examples on how to use oracle in playframework 2.0, I noticed that you should have a line similar to this one in application.conf:
jpa.dialect=org.hibernate.dialect.Oracle11gDialect
However, this (or any other version number I can come up with) gives an error :
PersistenceException: No Persistence provider for EntityManager named org.hibernate.dialect.Oracle10gDialect
I have already placed hibernate-3.3.2.jar in my lib folder, but somehow play is not using it.
Does anybody know how to fix this, so I can use oracle with the play! framework 2.0?

Deploying ojdbc14.jar in a code module for a FileNet code module

I'm trying to deploy a couple of jar files in a code module for an event action in FileNet P8 4.0 (the FileNet server runs on WebSphere 6.1). One of these jars is my custom code, and the other jar is the thin driver for Oracle called ojdbc14.jar (I also tried with ojdbc15.jar), the custom code uses the oracle jar in order to connect to a data source and get a connection using the JNDI name.
When the event action is executed (after a subscription is invoked) the code in my custom module is called OK, the problem occurs when my code needs to load classes from the Oracle jar, I get this cause:
ERROR - Mon Sep 21 16:42:17 UTC 2009 - com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object. [Root exception is java.lang.reflect.InvocationTargetException]
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:1000)
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookup(Helpers.java:705)
at com.ibm.ws.naming.jndicos.CNContextImpl.processResolveResults(CNContextImpl.java:2093)
...
Caused by: java.lang.NoClassDefFoundError: oracle.jdbc.driver.OracleLog
at com.ibm.ws.rsadapter.dbutils.impl.OracleUtilityImpl.setLogVolume(OracleUtilityImpl.java:85)
at com.ibm.ws.rsadapter.spi.InternalOracleDataStoreHelper.setProperties(InternalOracleDataStoreHelper.java:142)
at com.ibm.ws.rsadapter.spi.WSRdbDataSource.(WSRdbDataSource.java:846)
at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.setDataSourceProperties(WSManagedConnectionFactoryImpl.java:1947)
... 43 more
...
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleLog
at java.net.URLClassLoader.findClass(URLClassLoader.java:496)
at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:132)
at java.lang.ClassLoader.loadClass(ClassLoader.java:631)
at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:87)
at java.lang.ClassLoader.loadClass(ClassLoader.java:597)
... 48 more
Since I'm deploying the oracle jar with the code module, shouldn't FileNet should be able to find the class? Do you think I need to configure something else?
Thanks in advance.
Is it possible for your application to use WebSphere's own JDBC connection pools? When you set up a pool for a particulr database you get all the vendor-specific drivers installed there.
Generally, all manner of classpath and classloader confisions ensue when you try to place infrastructure code in your own applications. I don't know for certain that this is the case for your situation, but I do find taht staying on the known path in WebSphere tends to give the smoothest results.
I found the problem... somehow the ojdbc14.jar file got corrupted, so even when the classpath was correct and no matter what I tried to fix the problem, the problem was always there.
Thanks for the comments!

Resources