Entity Packaging and EntityManagerFactory

This tutorial exposes you to a variety of things:

The EJB3 specification requires that persistence unit definitions and entity classes and mappings are contained within a .jar archive.

persistence.xml

Each .jar file contains a persistence.xml file. The persistence.xml file defines datasources, the entity manager's name, and additonal vendor specific properties. See the docbook that comes with this distribution for more information, but you can see examples of it within resources/em1/META-INF/persistence.xml

EntityManagerFactory

EntityManagerFactory is a service that allows you to manually create and managed EntityManager instances. It is not recommended for you to use this feature as you should be letting the application server manage EntityManager instances. EntityManagerFactory's are really for out-of-container applications that use EJB persistence.

EntityManager

For information on looking up EntityManagers from EAR/WAR files, please see the ear tutorial.

Ear packaging

The EJB 3 specification defines a new module type for application.xml
<application>
  <module>
    <persistence>em1.jar</persistence>
  </module>

JBoss does not yet support this xml, so in the meantime, put .par files within an ejb module. i.e...

<module>
   <ejb>em1.par</ejb>
</module>

Building and Running

To build and run the example, make sure you have ejb3.deployer installed in JBoss 4.0.x and have JBoss running. See the reference manual on how to install EJB 3.0.
Unix:    $ export JBOSS_HOME=<where your jboss 4.0 distribution is>
Windows: $ set JBOSS_HOME=<where your jboss 4.0 distribution is>
$ ant
$ ant run

Buildfile: build.xml

prepare:

compile:

ejbjar:

run:
     [java] factory: oneFactory
     [java] manager: oneManager
     [java] factory: twoFactory
     [java] manager: twoManager