Close

XADatasource in JBossAS & Hibernate

If you have ever wondered how you can use an XA Datasource in your JBoss AS, this is the answer. First you need to define the XA Datasource in your JBossAS, it is as easy as creating an XML file like this:

XAOracleDS
true
false
oracle.jdbc.xa.client.OracleXADataSource

jdbc:oracle:thin:@monkeymachine:1521:jboss

jboss
password

org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter

jboss:service=TransactionManager

Then you need to copy this file to your default (or another profile in your JBossAS) deploy folder, tada! you have registered a JNDI registry for the XA Data-source of yours. Now the question is how to use it with Hibernate. Hibernate configuration files are usually something like:

oracle.jdbc.driver.OracleDriver
rms_owner
jdbc:oracle:thin:@localhost:1521:HBTTST
rms_owner
org.hibernate.dialect.Oracle10gDialect

in this hibernate file as you can see, all the variables required to connect to database are specified. However, now that you have created the Datasource you just need to point hibernate configuration file to the new Datasource file, something like:

org.hibernate.dialect.Oracle10gDialect

java:XAOracleDS

now you should be able to use Hibernate and it should be able to connect to your database flawlessly.

Please note that the connection datasource name in hibernate file is java:XAOracleDS and not XAOracleDS.

Leave a Reply

Your email address will not be published. Required fields are marked *