Java Reference
In-Depth Information
to use Apache Aries with one of the open or commercial application server integra-
tions—which we heartily recommend—setting up the datasources will be much less
verbose. In the interim, think of the process of setting up the datasources as a useful
exercise in advanced Blueprint.
Now that you have a datasource service, what can you do with it?
3.2.2
Creating a persistence bundle
The datasource groundwork allows you to move on to the real meat of the Fancy
Foods persistence. You set your datasources up to use in-memory databases, so you
don't need to worry about creating physical databases or writing lots of SQL to set
them up. It's still worth thinking, though, about what you're trying to model with the
database and what kind of data you want to store.
THE FANCY FOODS SCHEMA
The schema for modeling the Fancy Foods shop is
fairly straightforward—so straightforward, in fact, that
it contains only one small table. Figure 3.6 shows the
schema. You shouldn't infer anything from our tiny
schema about the general scalability of JPA in enter-
prise OSG i. We'll play with quite a small database, but
complicated databases can also be handled with ease.
Food
Name
Price
QuantityInStock
Figure 3.6 The schema for the
Fancy Foods database. It's prob-
ably not the most complex sche-
ma you're likely to see in your
career! The database only has
one table, representing a food.
Foods have a name, a price, and
a stock level.
DEFINING A PERSISTENCE UNIT
You tell JPA about your schema in two ways. The first is
in the persistence.xml file. This file is the heart of a JPA
application, whether it's running in Java SE, Java EE , or
enterprise OSG i. It sets up one or more persistence
units. Each persistence unit defines a relationship between a datasource and Java
classes that represent database tables (see figure 3.7).
We won't cover persistence units in too much detail, because an enterprise OSG i
persistence.xml file is pretty much the same as a Java EE persistence unit or even a Java
SE persistence unit. Listing 3.2 shows the persistence.xml for the Fancy Foods shop.
JPA
entity
manager
Persistence
unit
Entity
classes
Datasource
Database
Figure 3.7 The connection between a database and Java objects is managed by a JPA entity manager.
The persistence unit defines the relationship between the datasource and the classes.
Search WWH ::




Custom Search