Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

A typical Seam project (created with seam-gen or JBoss Tools) relies on the default HSQLDB data source that's included with the Embedded JBoss bootstrap configuration, which is assigned the JNDI name java:/DefaultDS. This may be fine if you are seeding the database before running your tests. However, if you need to test against an existing database, you will need to setup your own connection.

To establish your own connection, you need two things:

  1. a data source configuration file
  2. the appropriate JDBC driver.

Let's start with the data source configuration file. Create a standard JBoss data source configuration file ending in -ds.xml. The file prefix does not matter. Here, we are establishing a connection to a MySQL database.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE datasources PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
NOTE - Embedded JBoss does not support the <use-java-context>false</use-java-context> setting. In fact, if this element is present and set to false, Embedded JBoss will fail to start! Therefore, you will always address the JNDI name using the java:/ prefix in your persistence unit descriptor used for tests (in this case java:/MySQLDS).

Put this file in the bootstrap/deploy folder. The bootstrap folder mirrors a JBoss domain directory, so the deploy folder is roughly equivalent to server/default/deploy in a typical JBoss installation.

Next, configure the persistence unit descriptor (e.g., resources/META-INF/persistence-test.xml in seam-gen projects) to reference this data source. It's also wise to set the Hibernate dialect property, though it may not be necessary in all cases:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="" 
   <persistence-unit name="vehicles" transaction-type="JTA">
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
         <property name="" value="none"/>
         <property name="hibernate.transaction.manager_lookup_class"

Finally, you have to make sure the JDBC driver (in this case the MySQL driver) is available to Embedded JBoss. It just needs to be on the test classpath when TestNG executes. In seam-gen projects, that means simply placing it in the lib or lib/test folder.


Now you should be able to run your tests against your own database.