Java Reference
In-Depth Information
business logic. In addition, development, testing, and maintenance are easier
because the business logic is decoupled from the database.
Improved performance
Using an
ORM
framework also improves performance. The framework caches
objects, which reduces the number of database accesses. In addition, features such
as eager loading mean that the persistence framework can generate
SQL
state-
ments that are often much more efficient than those hand-written by developers.
Furthermore, unlike a developer, an
ORM
framework can do this consistently.
Improved portability
In addition to increasing productivity and performance, an
ORM
framework
increases portability across databases. The framework takes care of generating the
database-specific
SQL
statements, and migrating from one database to another is
usually as simple as setting a configuration parameter. In comparison, writing por-
table
SQL
by hand is extremely difficult.
Sometimes you must use SQL directly
Despite the benefits of an
ORM
framework, using
SQL
directly is sometimes the
only way to get good performance. You can use database-specific features such as
optimizer hints or Oracle's
CONNECT
feature to improve the performance of que-
ries. In addition,
SQL
lets you insert, delete, or update a large number of rows
with a single
SQL
statement. For example, an
INSERT
statement such as the follow-
ing inserts the results of querying one table into another table:
INSERT INTO DESTINATION_TABLE
SELECT …
FROM SOURCE_TABLE
WHERE …
In comparison, an
ORM
framework would typically have to perform the following
steps:
Execute a query, which returns a set of objects that are mapped to
SOURCE_TABLE
.
1
Create objects that are mapped to
DESTINATION_TABLE
.
2
Save those objects.
3
This would be very inefficient if the query returned a large number of rows. As
well as transferring the data from the database to the application and back again,
there is also the overhead of manipulating the Java objects.
Search WWH ::
Custom Search