Java Reference
In-Depth Information
placeholders and to construct beans from a
ResultSet
. It also includes support for
database-generated primary keys, automatic loading of related objects, caching,
and lazy loading. In this way, i
BATIS
eliminates much of the drudgery of executing
SQL
statements. As you will see in several chapters, including chapter 9, i
BATIS
can
considerably simplify code that executes
SQL
statements. Instead of writing a lot of
low-level
JDBC
code, you write an
XML
descriptor file and make a few calls to i
BA-
TIS
API
s.
2.4.3
Using a persistence framework
Of course, i
BATIS
cannot address the overhead of developing and maintaining
SQL
or its lack of portability. To avoid those problems you need to use a persis-
tence framework. A persistence framework maps domain objects to the database.
It provides an
API
for creating, retrieving, and deleting objects. It automatically
loads objects from the database as the application navigates relationships between
objects and updates the database at the end of a transaction. A persistence frame-
work automatically generates
SQL
using the object/relational mapping, which is
typically specified by an
XML
document that defines how classes are mapped to
tables, how fields are mapped to columns, and how relationships are mapped to
foreign keys and join tables.
EJB 2
had its own limited form of persistence framework: entity beans. How-
ever,
EJB 2
entity beans have so many deficiencies, and developing and testing
them is extremely tedious. As a result,
EJB 2
entity beans should rarely be used.
What's more, as I describe in chapter 10 it is unclear how some of their deficien-
cies will be addressed by
EJB 3
.
The two most popular lightweight persistence frameworks are
JDO
[
JSR12
][
JSR243
], which is a Sun standard, and Hibernate, which is an open
source project. They both provide transparent persistence for
POJO
classes. You
can develop and test your business logic using
POJO
classes without worrying
about persistence, then map the classes to the database schema. In addition, they
both work inside and outside the application server, which simplifies development
further. Developing with Hibernate and
JDO
is so much more pleasurable than
with old-style
EJB 2
entity beans.
Several chapters in this topic describe how to use
JDO
and Hibernate effectively.
In chapter 5 you will learn how to use
JDO
to persist a domain model. Chapter 6
looks at how to use Hibernate to persist a domain model. In chapter 11 you will
learn how to use
JDO
and Hibernate to efficiently query large databases and pro-
cess large result sets.
Search WWH ::
Custom Search