Java Reference
In-Depth Information
NOTE: APACHE ARIES LIMITATIONS For versions of Apache Aries JPA below 1.0,
or OSG i framework versions earlier than 4.3, entities aren't automatically
enhanced. The Open JPA documentation has instructions on build-time
enhancement. If you're using one of the application servers discussed in
chapter 13, rather than our little Aries assembly, the server may take care of
enhancing the entities at runtime.
THE PERSISTENCE MANIFEST
To achieve full container management of your persistence, you need to let the con-
tainer know that this is an OSG i persistence bundle by telling it about the persis-
tence.xml file in the bundle manifest:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Fancy Foods Persistence Bundle
Bundle-SymbolicName: fancyfoods.persistence
Bundle-Version: 1.0.0
Meta-Persistence:
Import-Package: fancyfoods.food;version="[1.0.0,2.0.0)",
javax.persistence;version="[1.1,2.0)",
org.apache.openjpa.util
The Meta-Persistence: header tells the JPA service where to look for the persis-
tence.xml file (which therefore doesn't need to be called persistence.xml). The
header must be specified for the bundle to be eligible for managed JPA , but the loca-
tion is optional. If no location is specified, it defaults to META-INF /persistence.xml,
the same as in the Java SE and Java EE cases.
As usual, the bundle also needs package imports, but not many. The persistence
bundle will provide implementations of the Fancy Foods API , so it will need to import
that package. It also needs the JPA API , but nothing else. Because of the OSG i services
approach, it doesn't need any implementation-specific packages.
Notice that the fancyfoods.persistence package isn't exported. In fact, no pack-
ages are exported. Data is persisted using JPA , but consuming code shouldn't have to
know these implementation details. In fact, consuming code shouldn't even have to
know that there's a fancyfoods.persistence bundle. How does anything get hold of
the persistence classes? Blueprint!
SETTING UP A PERSISTENCE SERVICE
Define a new interface, fancyfoods.food.Inventory , shown in the following listing.
To keep the interface separate from implementation, it should be packaged in the
fancyfoods.api bundle you wrote in chapter 2.
Listing 3.4
The interface for the food persistence service
package fancyfoods.food;
import java.util.List;
public interface Inventory {
 
Search WWH ::




Custom Search