-
1. Re: ClassCastException in Jboss EAP 6.4.0 when using non-jdbc compliant driver
sfcoy Aug 5, 2015 9:25 AM (in response to parag2386)Do the jars in question appear in both the war file and the module?
-
2. Re: ClassCastException in Jboss EAP 6.4.0 when using non-jdbc compliant driver
parag2386 Aug 5, 2015 9:39 AM (in response to sfcoy)yes.. same jars are in module and the war
-
3. Re: ClassCastException in Jboss EAP 6.4.0 when using non-jdbc compliant driver
jaikiran Aug 5, 2015 11:48 AM (in response to parag2386)1. Please post the entire exception stacktrace
2. As Steve hinted, you shouldn't have to package the database driver jars within your application. So getting rid of those jars from the .war should help, if what we are guessing is indeed the problem.
-
4. Re: ClassCastException in Jboss EAP 6.4.0 when using non-jdbc compliant driver
parag2386 Aug 5, 2015 12:52 PM (in response to jaikiran)I am getting classcast exception for same class which verifies its due to different classloaders for same jar. For this scenario, the same jar is put in module and war.
I cant remove the jars from module or war. The war uses some of its classes so I have the dependency on both sides , in modules as well as in war.
Is it possible to have a single classloader for both module and war??
-
5. Re: ClassCastException in Jboss EAP 6.4.0 when using non-jdbc compliant driver
jaikiran Aug 5, 2015 2:36 PM (in response to parag2386)Please do post the exact exception stacktrace. There's no point trying to guess what we are helping you with.
-
6. Re: ClassCastException in Jboss EAP 6.4.0 when using non-jdbc compliant driver
parag2386 Aug 6, 2015 9:36 AM (in response to jaikiran)The Driver will look like:
com.jdbc.NonJdbcdriver
The connection is called com.jdbc.NonJdbcConnection
And those are in a file called NonJdbcDriver.jar
I have created a module as:
com.test
Under folder com/test/main, I have put the NonJdbcDriver.jar.
This jar will be used to create datasource.
Following code I am using to invoke the datasource:
DataSource ds = (DataSource)initContext.lookup("java:jboss/datasources/ExampleDS");
Connection con = ds.getConnection();
The connection we received is an instance of WrappedConnection. This connection, we are unwrapping as:
Connection conwrap = ((WrappedConnection)con).getUnderlyingConnection();
The getUnderlyingConnection() method will give us NonJdbcConnection Object. To use it as NonJdbcConnection, we need to cast it as :
NonJdbcConenction con = (NonJdbcConnection)conwrap
At this point the we get a classcast exception saying:
ClassCastException: Cannot cast com.jdbc.NonJdbcConnection to com.jdbc.NonJdbcConnection
I tried to see the classloaders for "conwrap" and NonJdbcConnection. Although both are same classes but have different classloaders which gives this error.