« IIW2005 Program | Main | Virtual Rights Online Symposium »

Persistence Configuration in EJB 3.0

In EJB 3.0, persistence is done using plain old java objects (POJOs). As far as I know, JBoss is the only J2EE capable application server supporting EJB 3.0 at this point. In the JBoss implementation the Hibernate roots of persistent POJOs are still very much visable. That’s good news since that means that much of the Hibernate documentation can be used to understand EJB 3.0.

In JBoss, the default persitence properties are stored in

$JBOSS_HOME/server/all/deploy/ejb3.deployer/META-INF/persistence.properties

The meaning of most of the configuration parameters you see there can be found in the Hibernate configuration documentation.

By default, the persistence configuration on JBoss’s EJB3.0 says to create new tables each time the application is deployed and to drop tables when it’s undeployed:

hibernate.hbm2ddl.auto=create-drop

This means that your data will be lost each time you redeploy your application. Probably OK when you’re developing your entities, but not what you want for a production database. To change this, you can either change the line to read

hibernate.hbm2ddl.auto=update

Theoretically, you can override the default in your persistence.xml deployment descriptor:

<entity-manager>
  <name>Animal</name>
  <jta-data-source>java:/DefaultDS</jta-data-source>
  <properties>
    <property name="hibernate.hbm2dll.auto"  Value="update"/> 
  </properties>
</entity-manager>

I found, however, in a few simple tests, that this didn’t work.

The default data source in JBoss is the Hypersonic database. This is an easy way to get going. JBoss stores the data in

$JBOSS_HOME/server/all/data/hypersonic

with the name localDB. This name, along with other configuration parameters for the Hypersonic DB, which is given the JNDI name DefaultDS can be found in this file:

$JBOSS_HOME/server/all/deploy/hsqldb-ds.xml   

Posted by windley on October 3, 2005 8:05 AM

See related posts:

3 Comments

Comment from MikeD at October 3, 2005 11:01 PM

You may have mis-spelled the property name:
<property name="hibernate.hbm2dll.auto" Value="update"/>

Try
<property name="hibernate.hbm2ddl.auto" Value="update"/>

Comment from Phil Windley at October 4, 2005 7:41 AM

Heh. Yeah, that's a typo.

One other typo that needs to be corrected: Value should be lower case. So, the right poroperty is:

<property name="hibernate.hbm2ddl.auto" value="update"/%gt;

Comment from Anon at October 4, 2005 9:03 AM

Oracle and SolarMetric Kodo also have EJB 3 persistence implementations. Kodo isn't an application server -- it just implements the persistence portion of the spec (and lots of advanced extensions) to be used outside of a container, or to integrate with the application server of your choosing.