Java Reference
In-Depth Information
4.8 Summary
Business logic that is implemented using the Domain Model pattern consists of a
fine-grained web of interconnected objects. Many of those objects are persistent,
which means that when the application handles a request it must transfer objects
to and from the database. Storing domain objects in a database is a remarkably dif-
ficult problem. One reason is that any OO concepts such as inheritance have no
equivalent database concept. Another challenge is implementing transparent per-
sistence, which means that persistent objects are unaware that they are persistent.
Persisting a domain model almost always requires an ORM framework because
it is simply too difficult to do yourself with JDBC . An ORM framework provides fea-
tures such as declarative object/relational mapping; an API for creating, finding,
updating, and deleting persistent objects; a query language; caching to improve
performance; and support for transactions. Two popular ORM frameworks are
JDO and Hibernate, which despite their numerous differences provide a compara-
ble set of features.
Because JDO and Hibernate provide transparent persistence, the only domain
model classes that call the persistence framework API s to create, find, and delete
persistent objects are the repositories, which define methods for these tasks. We
can use the Spring ORM template classes, which are wrappers around the ORM
framework API s, to significantly simplify the implementation of these classes. Most
repository methods are easy to test one-liners that call a template class conve-
nience method.
It is important to test the persistent classes and repositories because a variety of
bugs are caused by the domain model, the object/relational mapping, and the
database schema getting out of sync. Effective testing requires using a combina-
tion of different kinds of tests. Some tests (such as those that verify that persistent
objects can be created, updated, deleted, and queried) must use the database.
However, because testing with a database is slow, it's important to test as much of
the persistence layer as possible without it.
Now that you have learned about ORM concepts and the basics of Hibernate
and JDO , the next chapters examine those ORM frameworks in more detail, start-
ing with JDO .
 
Search WWH ::




Custom Search