Java Reference
In-Depth Information
or join tables. JDO and Hibernate can also run outside of the application server,
which means that you can test your persistent business logic without deploying it
in a server. You can, for example, simply run tests from within your integrated
development environment ( IDE ).
Encapsulating the calls to the persistence framework
Even though Hibernate and JDO provide transparent persistence, some parts of
an application must call the JDO and Hibernate API s to save, query, and delete
persistent objects. For example, TransferService must call the persistence frame-
work to retrieve the accounts and create a BankingTransaction . One approach is
for TransferService to call the persistence framework API s directly. Unfortu-
nately, this would couple TransferService directly to the persistence framework
and the database, which makes development and testing more difficult.
A better approach is to encapsulate the Hibernate or JDO code behind an inter-
face, as shown in figure 1.3. The persistence framework, which in this example is
TransferService
BankingTransaction transfer(fromId, toId, amount)
Account
<<interface>>
Account
Repository
<<interface>>
BankingTransaction
Repository
debit(amount)
credit(amount)
Banking
Transaction
findAccount(id)
createTransaction(…)
HibernateBanking
Transaction
Repository
Hibernate
Account
Repository
findAccount(id)
createTransaction(…)
Hibernate
Figure 1.3 Using repositories to encapsulate the persistence framework
hides the persistence details from the rest of the application.
 
Search WWH ::




Custom Search