JBoss EAP 6.1 standlone server
Application deployed as a war file throws a runtime exception
java.lang.ClassCastException: oracle.sql.ARRAY cannot be cast to oracle.sql.ARRAY
at line
oracle.sql.ARRAY obj = (oracle.sql.ARRAY) rs.getObject("RATINGOBJ");
JDBC libary included is ojdbc6.jar (WEB_INF/lib). All libraries are included in the war file and there are no "global" libaries setup on the server. I have verified no other jdbc libraries are included anywhere in the app.
In order to create a JDBC datasource, i created a deployment for ojdbc6.jar. This is the only possible source of conflict i can think of. When i remove the ojdbc6.jar from the war file, i get a ClassNotFound exception in place of the ClassCastException.
Every other part of the app works fine except this line. How do i debug this any further?
I am not sure why loading from web-inf/lib will not work. Most likely the classloader's are different.
Do the first two steps for diagnosis. After that try one of the two alternatives below to fix the problem.
1) Check if the class loaders are the same by comparing the rs.getObject().getClass('RATINGOBJ').getClassLoader()
and oracle.sql.ARRAY.class.getClassLoader()
If you do equals
between the two classloaders, it should return false as it looks that the classloaders are different.
Check an explanation at
ClassCastException when casting to the same class
This problem has already been reported earlier in another forum at https://forums.oracle.com/message/9330314. Moving jars around in jboss will still result in same problems.
2) Find out the source jars from where the classes are getting loaded and remove the jar that you dont need.
Find the jars for the two different classes by checkingrs.getObject().getClass('RATINGOBJ').getProtectionDomain().getCodeSource().getLocation()
oracle.sql.ARRAY.class.getProtectionDomain().getCodeSource().getLocation()
- Determine which JAR file a class is from
Possible Solutions:
a) If you need both the jars, y'll have to move the Jar of
rs.getObject().getClass('RATINGOBJ').getProtectionDomain().getCodeSource().getLocation()
and create the module as specified at http://www.javaworld.com/community/node/8184.
b) If you still cant get classes to be loaded as you expect, Specify the library in jboss server library.
c) The last solution to force classes to be loaded from a particular jar is by specifying the jar in the bootclasspath.
You should not have any JDBC driver JARs at the WEB-INF/lib level. Java EE app servers need them to be at the app server level.
Move it into the default server /lib directory and see if that's better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With