Java Reference
In-Depth Information
At the deployment phase, you specify the primary key class in the entity bean's deployment descriptor,
as shown next:
<entity>
<ejb-class>PartEBean.PartBean</ejb-class>
<home>PartEBean.PartHome</home>
<remote>PartEBean.Part</remote>
<persistence-type>Bean</persistence-type>
<prim-key-class> PartEBean.PartKey</prim-key-class>
… …
</entity>
The entity bean's deployment descriptor specifies that the PartEJB uses bean-managed persistence
and that its primary key class is PartKey . In the next chapter , you see that the deployment descriptor
for a CMP entity bean contains much more contents than that for a BMP bean.
In the rest of this chapter, a BMP entity bean, MemberEJB , is built as an example. A MemberEJB
instance represents a row in the Member Table. The Member Table has four columns, as shown in
Table 21-1 . Since the Member Table has a simple primary key, member_id , the java.lang.String
class is used as the MemberEJB 's primary key class.
Table 21-1: Sample Data Stored in the Member Table
member_id
last_name
first_name
membership_year
m001
Dole
Jane
20
m002
Dole
John
4
m003
Corleone
Fredo
12
m004
Smith
Mike
7
Create and Delete Entity Objects via Entity Beans
With BMP, the bean developer writes all the database-access calls. These database access-operations
include the creation and deletion of the business objects, the synchronization between the attribute
values of entity beans and the state of the corresponding business object, and the search for specific
business objects.
The EJBHome interface and EntityBean interface specify the life-cycle methods for these operations,
and the bean developer implements these methods by using database-access APIs such as JDBC. As
an example, the home interface of the MemberEJB is shown in Listing 21-2 . A Member EJB represents
a row in the Member Table, which has these four columns, as seen in Table 21-1 :
 
member_id
 
last_name
 
first_name
 
membership_year .
Listing 21-2: Home interface of MemberEJB
/** MemberEJB Home Interface
* @author: Andrew Yang
* @version: 1.0
*/
package java_database.MemberEBean;
Search WWH ::




Custom Search