Java Reference
In-Depth Information
Third, the persistence framework must allow the application to efficiently
select a range of rows from a large result set without loading it into memory. In
EJB 3 , executing a query returns a list and you can specify the range of results to
return by calling Query.setFirstResult() and Query.setMaxResults() . However,
the specification does not give you any control over how the query is executed.
Furthermore, EJB specification does not describe whether the result set is pro-
cessed lazily or eagerly. Consequently, EJB 3 implementations will vary in how effi-
ciently they can handle large result sets.
Finally, it is extremely helpful if the persistence framework supports Hiber-
nate-style criteria queries, which as you will see in chapter 11, are a good way to
construct queries dynamically. Unfortunately, EJB 3 lacks support for criteria que-
ries and the application must dynamically construct a query by concatenating
query fragments together, which results in messy code that is difficult to maintain.
10.5.4
Implementing the concurrency patterns
As you will see in chapter 12, most enterprise applications have to deal with data-
base concurrency at the database transaction level by using optimistic locking,
pessimistic locking, or serializable transactions. Optimistic locking is the only con-
currency mechanism currently supported by the EJB 3 specification. However, a
note in the specification states that a future version will describe how to control
the transaction isolation level. The EJB 3 specification does not mention pessimis-
tic locking, but presumably vendors will provide it as an extension.
In addition to database transaction-level concurrency mechanisms, many
applications must also use the offline locking patterns, which are described in
chapter 13, to handle concurrency in use cases that consist of multiple transac-
tions. The two patterns are the Pessimistic Offline Lock pattern, which is applica-
tion-level locking, or the Optimistic Offline Lock pattern, which is an extension of
optimistic locking. It is easy to implement the Optimistic Offline Lock pattern
using detached entity beans. Similarly, implementing the Pessimistic Offline Lock
pattern is also straightforward because it does not rely on any persistence frame-
work features.
10.6 Summary
EJB 3 is a tremendous improvement over EJB 2 . Because EJB 3 beans do not imple-
ment special interfaces, they are POJO s, which makes them much easier to write.
EJB 3 entity beans are intended to be the Java persistence standard and can run
both inside and outside the EJB container. They can also can be detached and
 
 
 
 
Search WWH ::




Custom Search