Java Reference
In-Depth Information
<execution>
<execution>
<id>
<id> jboss-deploy </id>
</id>
<phase>
<phase> pre-integration-test </phase>
</phase>
<goals>
<goals>
<goal>
<goal> deploy </goal>
</goal>
</goals>
</execution>
</goals>
</execution>
<execution>
<execution>
<id>
<id> jboss-undeploy </id>
</id>
<phase>
<phase> post-integration-test </phase>
</phase>
<goals>
<goals>
<goal>
<goal> undeploy </goal>
</goal>
</goals>
</execution>
</goals>
</execution>
</executions>
</executions>
</plugin>
</plugin>
The jboss-as-maven-plugin is configured to run after the WAR is built, but before the unit
tests are run. It uses the Wildfly remote deployment interface to automatically deploy our
WAR to the Wildfly application server. We'll see later how to start the example.
The EJBs
The EJB code is very similar to ex10_2 from Chapter 24 , except the code has been expanded
to save created order entries into a relational database instead of an in-memory map. Like all
of our previous examples, the JAXB classes that define our XML data format live in the
com.restfully.shop.domain package. A separate parallel Java package,
com.restfully.shop.persistence , was created for the example's JPA classes. These JPA
classes are almost a carbon copy of the JAXB ones, except they are using JPA annotations to
map to a relational database.
You could use JAXB and JPA annotations together within one class hierarchy, but this isn't
the best idea, as there are a few problems you might encounter. The first has to do with how
JPA works. Objects like the OrderEntity have relationships to other classes like
LineItemEntity , ProductEntity , and CustomerEntity . In JPA, it is common to lazy-load
these objects as their object graphs are traversed. This can save on database access time. The
problem where JAX-RS is concerned is that the JAX-RS runtime will usually turn the Java
object into an XML document outside the scope of an EJB request. This might cause lazy-
load exceptions when JAXB tries to traverse the entire object graph.
You can write your code so that it is careful not to introduce lazy-load exceptions, but there
is one other major problem you may encounter. You will often want to support older clients
that use older versions of the XML format. This can cause a divergence between your XML
Search WWH ::




Custom Search