Specifying driver-class or datasource-class for non-XA JDBC datasource pools in JBoss EAP
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7
- 6
- All database types
Issue
- Should a
driver-classordatasource-classbe specified for non-XA JDBC pools?
Resolution
Configuring non-XA Pools
- For JDBC 4 compliant drivers, neither a
driver-classnor adatasource-classare required or recommended in most cases. - For drivers which are not JDBC4-compliant, it may be necessary to specify a
driver-classor adatasource-classwhen configuring a non-XA pool.- Consult the 3rd party vendor documentation for the recommended class.
- In certain cases, use of a
datasource-classmay be required if 3rd party functionality is available only when using an implementation ofjavax.sql.DataSource. - It is permissible to define either a
datasource-classor adriver-classbut never both.- Note that if using a static driver module the same rule applies across the
datasource(pool) anddriver(entry in thedriverssubsection). - It is invalid to specify a
driver-classordatasource-classin the datasource (pool) and also reference adriverentry which includes either adatasource-classordriver-class.
- Note that if using a static driver module the same rule applies across the
Configuring both XA and non-XA Pools using a Static Driver Module
If one or more XA pools are to be defined, they may share a single `driver` entry in the `drivers` subsection with one or more non-XA pools.
- A
driverentry in thedriverssubsection is used to declare a driver that is provided as a static module in the JBoss EAP installation instead of a simple single-jar based deployment. The static module will contain one or more jar files which make up the 3rd party vendor's JDBC implementation. - It is not uncommon (since non-XA pools do not usually require any explicit connection provider class specification) to configure a
driverwhich lists only anxa-datasource-classand which is shared by both XA and non-XA pools. - In such cases, non-XA pools will not use1 the
xa-datasource-class- but will, instead, use the defaultjava.sql.Driverimplementation or thedriver-classordatasource-classif specified.
1
The xa-datasource-class may be validated during load of the configuration even if no XA pool is defined.
Root Cause
- There are two alternatives for connecting to a database when using a non-XA pool:
- Using a class which implements Content from docs.oracle.com is not included.java.sql.Driver
- Using a class which implements Content from docs.oracle.com is not included.javax.sql.DataSource
- XA pools require specification of a class which implements Content from docs.oracle.com is not included.javax.sql.XADataSource
- For non-XA pools, implementations of
java.sql.Driverare usually preferred to implementations ofjavax.sql.DataSourcebecause theDriverinterface provides a standard mechanism for property configuration.- Note that, while both serve the same purpose (creating connections to a database), implementations of
DriverandDataSourceare not interchangeable. - An error may occur if a
DataSourceimplementation class is specified as adriver-classor if aDriverimplementation class is specified as adatasource-class.
- Note that, while both serve the same purpose (creating connections to a database), implementations of
- The connection provider for XA pools must be provided using the
xa-datasource-classand this property is also not interchangeable with eitherdriver-classordatasource-class. - JDBC 4 compliant JDBC drivers (i.e. 3rd party vendor provided jar files which bundle an implementation of the JDBC 4 specification) specify the preferred driver in
META-INF/services/java.sql.Driver. - JBoss EAP will automatically select an appropriate implementation of the
java.sql.Driverclass for non-XA pools if neitherdriver-classnordatasource-classare explicitly included in either thedatasourceordriverdefinition.
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.