Java Reference
In-Depth Information
Session and message-driven beans must be deployed
Apart from the limitations described earlier, EJB 3 entity beans are fairly easy to
use: develop your POJO s and annotate them. However, session and message-
driven beans are different beasts entirely. Even though they are POJO s, you must
deploy them in the EJB container, which slows down the edit-compile-debug cycle.
Furthermore, unless they have a remote interface you must implement the tests
using Cactus [Cactus] and deploy them in the application server as well, which is
an added source of complexity. In comparison, executing tests in a Spring-based
application is convenient and fast.
Development environment complexity
Another drawback of developing with EJB 3 is that you must deal with the added
complexity of incorporating a full-blown application server in your development
environment even if your application does not use other parts of the J2EE stack
such as JMS . EJB 3 shields you from some of the complexity, but it is still there,
lurking beneath the surface.
As you can see, even though EJB 3 is definitely much easier to use than EJB 2 , it
still has some significant limitations. Let's now look at how to use EJB 3 to imple-
ment an application. In the next section you will learn how to persist a domain
model with EJB 3 . After that we describe the different ways to implement a façade
in an EJB 3 application.
10.2 Implementing a domain model with EJB 3
In this section you will learn how to use EJB 3 to persist a domain model. We use the
domain model for the Place Order use case that was developed in chapter 7 as an
example. Figure 10.2 shows the domain model classes that we will be discussing.
You will learn how to define the O/R mapping for the domain model entities,
such as PendingOrder and Coupon . We explain how to implement the
EJB3RestaurantRepository , and also briefly describe how to write tests for EJB 3
entity beans. You will see examples of how the limitations we discussed earlier in
section 10.1.2 can impact the design of even a simple domain model.
10.2.1
Mapping the classes to the database
Let's look at some example classes that show how to configure entities beans and
define their O/R mapping. You will see that some aspects of persisting a POJO
domain model using EJB 3 are straightforward. You just have to annotate the
 
 
 
 
 
 
Search WWH ::




Custom Search