Java Reference
In-Depth Information
// Always return null
return null;
}
public void ejbPostCreate(String yachtName, String builder, String
engineType,
int capacity, int maxVelocity) {
// nothing to code
}
// Business Methods
public YachtSession createYachtSession() {
YachtSession session = null;
try {
YachtSessionHome home = (YachtSessionHome)ctx.lookup(
"java:comp/env/ejb/YachtSessionEJB");
// In order to create a YachtSession instance, we must pass
// in a reference to this Yacht EJB's remote stub.
session = (YachtSession)home.create((Yacht)context.getEJBObject());
} catch (Exception e) {
System.out.println("Failed to create YachtSession: " + e);
}
return session;
}
}
You may be impressed by how little you have to code. Compared with the BMP implementation given in
Listing 21-6 , the CMP implementation class has much less code. This leads to one of the major
advantages of CMP entity bean — a fast development cycle.
From Listing 22-3 , you see that the implementation classes have defined five abstract getters and
five abstract setters for the five persistent fields. The concrete implementation is automatically
generated by the EJB container based on the information provided in the deployment descriptor. As an
example, the YachtEJB 's deployment descriptor for WebLogic Application Server 6.0 is shown in
Listing 22-4 . If you use another application server, your deployment descriptor files may look slightly
different. When your application contains multiple EJBs, and some other components such as servlets,
the deployment descriptor can be very long and complex. Therefore, you should never write your
deployment descriptors with a text editor. Instead, always use the deployment tool provided by your
application server. These XML files should always be generated by your application server, just as all
the concrete implementations of the abstract EJB methods are automatically generated by EJB
container.
Note
Do not use a text editor to write a deployment descriptor. Use the deployment tool
provided by your application server.
Listing 22-4: Deployment descriptor for YachtEJB
# First DD File - J2EE Standard
Search WWH ::




Custom Search