Java Reference
In-Depth Information
You might still have to use SQL even if there are no significant performance
benefits. Consider the policies laid down by your DBA . He might require you to
maintain your application's SQL statements in separate files so that he can tune
them. Or, your DBA might require your application to access the database using
stored procedures. Consequently, you cannot let the ORM framework generate
SQL for you.
Some ORM frameworks provide support for executing SQL statements directly.
Hibernate and JDO allow you to write native SQL queries. In addition, Hibernate
lets you specify the SQL statements to use for creating, updating, and deleting
individual objects. Hibernate and some JDO implementations provide some sup-
port for stored procedures. Hibernate also supports certain kinds of bulk updates
and deletes. But, even though these features are extremely useful, sometimes you
must execute SQL statements using either JDBC or i BATIS .
ORM limitations
ORM frameworks are not all-powerful. They have limitations that can prevent you
from mapping your domain model to a database schema in exactly the way you
want it to be done. This can be particularly challenging when you're working with
a legacy schema. For example, a common performance optimization is to elimi-
nate joins by denormalizing the schema and storing the first N items of a one-to-
many relationship in the parent table. In this kind of situation, you typically have
to mirror the database structure in the domain model, which makes the code
more complicated.
You might also design a domain model that cannot be mapped to the desired
database schema. If this happens, you must change either the domain model or
the database schema. For example, I once worked on an application that had a
class hierarchy of embedded objects that I wanted to map to the parent object's
table. The ORM framework did not support this mapping, and so I had to map the
class hierarchy to its own table. In this instance, this limitation was only a minor
issue because I had control over the database schema. But if the database schema
had been fixed, I would have needed to change the domain model.
Despite their limitations, ORM frameworks are an extremely useful technology
in many applications. They significantly increase productivity of developers by
reducing the amount of database access code that must be rewritten. Moreover,
they often increase the performance and portability of an application.
 
 
 
 
 
Search WWH ::




Custom Search