Ejb+3+Tutorial+2+-+Optional+Data+Source+Configuration

The persistence.xml file mentions the possibility of using your own data source rather than the default data source to hit a different database.

When you use the embedded container, it looks for a file called embedded-jboss-beans.xml for its datasources (and several other things). In the one that ships with the ALPHA 9 release, you'll see the following two entries near the bottom: code format="xml"  org.hsqldb.jdbcDriver jdbc:hsqldb:. sa java:/DefaultDS 0 10 1000 100000      

 <constructor factoryMethod="getDatasource"> <factory bean="DefaultDSBootstrap"/> code

To create your own data source, you basically copy both of these and update the values accordingly. Here is one example that uses HSQL with a local server: code format="xml" <bean name="HypersonicLocalServerDSBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource"> <property name="driverClass">org.hsqldb.jdbcDriver <property name="connectionURL">jdbc:hsqldb:hsql://localhost/xdb <property name="userName">sa <property name="jndiName">java:/HypersonicLocalServerDS <property name="minSize">0 <property name="maxSize">10 <property name="blockingTimeout">1000 <property name="idleTimeout">100000 <property name="transactionManager"> <inject bean="TransactionManager"/> <property name="cachedConnectionManager"> <inject bean="CachedConnectionManager"/> <property name="initialContextProperties"> <inject bean="InitialContextProperties"/> <bean name="HypersonicLocalServerDS" class="java.lang.Object"> <constructor factoryMethod="getDatasource"> <factory bean="HypersonicLocalServerDSBootstrap"/> code

To use this, you need to do two things. Update persistence.xml and start a HSQL server.

Replace the following line: code format="xml" <jta-data-source>java:/DefaultDS</jta-data-source> code
 * Update persistence.xml**

With this one: code format="xml" <jta-data-source>java:/HypersonicLocalServerDS</jta-data-source> code

To start an HSQL server, you can use the following steps: code java -cp ../lib/hsqldb.jar org.hsqldb.Server -database.0 file:mydb -dbname.0 xdb code
 * 1) Under the place where you extracted HSQL (C:\libs\hsqldb if you used the same directories as the tutorial), create a new directory called "databases".
 * 2) Change to that directory
 * 3) Use the following command to start the HSQL server: