12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Container-managed persistence and Relationships<br />

Container-managed persistence and Relationships<br />

<strong>Borland</strong>'s EJB container provides tools that generate the database access calls at the<br />

time that the entity bean is deployed; that is, when the entity bean is installed into a<br />

Partition. The tools use the deployment descriptors to determine the instance fields for<br />

which they must generate database access calls. Instead of coding the database<br />

access directly in the bean, the bean provider of a container-managed entity bean must<br />

specify in the deployment descriptor those instance fields for which the container tools<br />

must generate access calls. The container has sophisticated deployment tools capable<br />

of mapping the fields of an entity bean to its data source.<br />

Container-managed persistence has many advantages over bean-managed<br />

persistence. It is simpler to code because bean provider does not have to code the<br />

database access calls. Handling of persistence can also be changed without having to<br />

modify and recompile the entity bean code. The Deployer or Application Assembler can<br />

do this by modifying the deployment descriptor when deploying the entity bean. Shifting<br />

the database access and persistence handling to the container not only reduces the<br />

complexity of code in the bean, it also reduces the scope of possible errors. The bean<br />

provider can focus on debugging the business logic of the bean rather than the<br />

underlying system issues.<br />

The EJB 2.0 specification allows entity beans that use container-managed persistence<br />

to also have container-managed relationships among themselves. The container<br />

automatically manages bean relationships and maintain the referential integrity of<br />

these relationships. This differs from the EJB 1.1 specification, which only allowed you<br />

to expose a bean's instance state through its remote interface.<br />

Just as you defined container-managed persistence fields in a bean's deployment<br />

descriptor, you can now define container-managed relationship fields in the<br />

deployment descriptor. The container supports relationships of various cardinalities,<br />

including one-to-one, one-to-many, and many-to-many.<br />

Implementing an entity bean<br />

Implementing an entity bean follows the rules defined in the EJB 1.1 and 2.0<br />

specifications. You must implement a home interface, a remote interface or a local<br />

interface (if using the 2.0 container-managed persistence), and the entity bean<br />

implementation class. The entity bean class must implement the methods that<br />

correspond to those declared in the remote or local and home interfaces.<br />

Packaging Requirements<br />

Like session beans, entity beans can expose their methods with their interfaces. Each<br />

Entity Bean must also have corresponding entries in its JAR's deployment descriptors.<br />

The standard deployment descriptor, ejb-jar.xml contains essentially three different<br />

types of deployment information. These are:<br />

1 General Bean Information: This corresponds to the elements<br />

found in the descriptor file and is used for all three types of beans. This information<br />

also includes information on the bean's interfaces and class, security information,<br />

environmental information, and even query declarations.<br />

2 Relationships: This corresponds to the elements found in the<br />

descriptor file and applies to entity beans using CMP only. This is where containermanaged<br />

relationships are spelled out.<br />

3 Assembly Information: This corresponds to the element<br />

which explains how the beans interact with the application as a whole. Assembly<br />

information is broken down into four categories:<br />

112 BES Developer’s Guide

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!