Java Reference
In-Depth Information
JDOPersistenceTests and HibernatePersistenceTests make it easier to write
tests for persistent objects and queries. They take care of opening and closing the
PersistenceManager and Session ; create the HibernateTemplate and JdoTemplate ;
and provide methods for managing transactions. In chapters 5 and 6 you will see
examples of tests that use these classes.
Automated testing is an important tool for ensuring that the application works
correctly. It's something that we all need to do regularly (along with flossing). But
when we are developing an application we also need to consider performance.
Let's now look at how to optimize the performance of an application that uses
JDO and Hibernate.
4.6 Performance tuning JDO and Hibernate
The database is often the bottleneck in an enterprise application, and to achieve
good performance it's essential to tune the persistence layer and minimize the
number of calls to the database. We saw in section 4.3 that JDO and Hibernate
provide two main ways of improving performance. One way is to use eager load-
ing and to load related objects using a single SELECT statement. The other way is to
use process-level caching of objects and queries. An application can use both
eager loading and a process-level caching, but as you will see later on in this sec-
tion, using a process-level cache affects how you use eager loading.
I begin this section by describing the SQL statements that Hibernate or JDO
application will use during the execution of an example use case without doing
any performance tuning. You will then see how eager loading can be used to opti-
mize performance. Finally, I describe how to use a process-level cache to optimize
performance. This section doesn't get into the details of optimizing performance
when using a particular framework. For that, please see chapter 5, which describes
how to optimize performance with JDO , and chapter 6, which describes how to
improve performance of a Hibernate application.
4.6.1
Without any tuning
Let's begin by considering what happens during the Place Order use case when
the user enters the payment information. The application first calls PlaceOrder-
Service to validate the payment information and update the pending order. It
then displays the pending order, its restaurant, and its line items on the confirma-
tion screen. By default, JDO and Hibernate will load all objects lazily, which means
that the call to PlaceOrderService will load only the PendingOrder . The restaurant
 
 
 
 
Search WWH ::




Custom Search