Java Reference
In-Depth Information
The disadvantage of this approach is that a future version of Hibernate could
behave differently and break your application. So beware!
Benefits and drawbacks of managing transactions in the business tier
The main benefit of managing transactions in the business tier is that it simplifies
the presentation tier. You don't need to write presentation logic that supports
retries and buffers the response. However, there are the following drawbacks:
Retrying transactions with Hibernate is difficult —As we described earlier, retry-
ing transactions in a Hibernate application is tricky. Neither of the options
we've outlined is ideal. Using multiple sessions per request can be inefficient,
and relying on Session.clear() to reinitialize the session is a little risky.
There is a lack of transactional consistency —Because a JSP page accesses lazily
loaded objects outside of the transaction, it could potentially get an incon-
sistent view of the database. See chapter 12 for an in-depth discussion of
transaction isolation levels.
Using JTA transactions in a JDO application isn't possible— As we explained ear-
lier, a JDO PersistenceManager cannot participate in a JTA transaction
because it is opened before the transaction begins.
That's it! We have reached the end of a section that covers a fairly difficult topic.
As you've learned, there are several tricky issues that you must resolve when using
the Exposed Domain Model pattern. When using this pattern, neither Hibernate
nor the servlet API handle transactions retries as well as we would like. However,
despite these drawbacks it is worthy of consideration for some applications. Let's
look at an example.
8.4 An example of the Exposed Domain Model pattern
In this section we'll dive into the details of implementing the Place Order use case
with the Exposed Domain Model pattern. You will learn how to implement this pat-
tern with Spring, JDO , and Hibernate. The design, which is shown in figure 8.8,
consists of the following components:
Servlets and JSP pages that handle HTTP requests and generate responses by
calling the domain model
A Spring servlet filter that manages persistence framework connections
A Spring TransactionInterceptor , which wraps the PlaceOrderService and
manages transactions with the PlatformTransactionManager
 
 
Search WWH ::




Custom Search