JBoss EAP (all versions) wraps the datasource and connection implementation classes provided by third party JDBC drivers (e.g. those supplied by Oracle or Microsoft) in order to provide connection pooling and transaction integration. Consequently, the class instances returned by DataSource.getConnection() and other related APIs cannot be directly cast to vendor specific class types.
Note that the wrapping implementation classes/packages have changed between JBoss EAP 5 and JBoss EAP 6.
Determining the Driver Class for JDBC 4 Style Unwrap
Use the JBoss implementation specific wrappers (temporarily) to obtain the underlying connection and check the class type
java.sql.Connection wrapped = dataSource.getConnection();
java.sql.Connection unwrapped = org.jboss.jca.adapters.jdbc.WrappedConnection.class.cast(connection).getUnderlyingConnection();
Using the JDBC 4 mechanism is preferred over the older (EAP 4/5) style of unwrapping connections. Using the JDBC mechanism frees the application from the requirement to bind to the underlying JBoss implementation classes which are subject to change. Avoiding direct dependency on the IronJacamar implementations prevents warnings related to the use the private org.jboss.ironjacamar.jdbcadapters module.
Thanks for the reply and the tip, but we are looking for an answer to our question, which is:
- We are running JBoss 6.1 using JDK7.
- The connection we get when we call dataSource.getConnection() is of type org.jboss.resource.adapter.jdbc.jdk6.WrappedDataSourceJDK6
- Why is the class WrappedDataSourceJDK6 and not WrappedDataSourceJDK7?
- Is there a way to configure it?
- Are there any risks to using WrappedDataSourceJDK6 when running JBoss under JDK7?