Java Reference
In-Depth Information
RESTAURANT_NAME column to the PLACED_ORDER table, we would have to map that
column to a restaurantName field in the Order class.
Although it is easy to define the O/R mapping for denormalized columns,
changing the object model to reflect the denormalized database schema intro-
duces additional complexity and maintenance problems. For example, because
the denormalized column is maintained by a trigger, the corresponding field will
not have a valid value in a newly created object or during in-memory testing
unless the domain model contains extra code to initialize it.
Here is an example of the kind of code you need to write in your domain
model objects to support denormalized columns:
public class Order {
private String restaurantName;
public Order(String externalOrderId, Address address,
Date date, Restaurant restaurant,
PaymentInformation information) {
this.restaurantName = restaurant.getName();
}
public String getRestaurantName() {
return restaurantName;
}
}
In this example, the Order class has a restaurantName field that is initialized by the
constructor, which calls Restaurant.getName() . Although this is a minor change,
lots of little changes such as this can be messy.
11.3.5
Implementing paging
The fourth and final part of implementing dynamic paged queries with Hibernate
and JDO is handling pagination. A query such as View Orders can potentially
return a large number of objects. We definitely do not want Hibernate or JDO to
instantiate a list containing the entire result set, especially if the application will
only display a subset of the elements. Instead, we must ensure that the persistence
framework does one of two things:
Execute a SELECT statement that uses a ROWNUM -like feature to return only the
required range of rows
Execute a SELECT statement that returns all rows and then navigate the JDBC
ResultSet selecting the required rows
 
 
Search WWH ::




Custom Search