Entity Packaging and EntityManagerFactory
This tutorial exposes you to a variety of things:
- .par files
- persistence.xml files
- EntityManagerFactory
.par files
The EJB3 specification requires that there be a .par archive that defines
what a persistence unit is. A persistence unit is a set of classes which
map to a particular database. JBoss EJB 3.0 allows you to put entity
classes and mappings directly within a .ejb3 archive, which is not allowed by
the specification.
persistence.xml
Each .par file may contain 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.
Ear packaging
The EJB 3 specification defines a new module type for application.xml
<application>
<module>
<persistence>em1.par</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