Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Section 4. Example 1: Defining CMP fields
Defining CMP fields in the local interface
The first step is to define CMP fields. A CMP field is a field you want the EJB container
to persist. An entity bean has CMP fields that are virtual fields. Unlike CMP 1.0, in CMP
2.0 you don t define member variables for CMP fields. Instead, using the JavaBeans
property naming convention, you define virtual getter and setter methods
corresponding to name of the fields that you want to persist. You add these abstract
methods in both the interface and the implementation. This concept is demonstrated in
the following code:
package com.rickhightower.auth;
import javax.ejb.EJBLocalObject;
public interface LocalUser extends EJBLocalObject {
public String getEmail();
public String getPassword();
}
Since you only defined getters for the
UserBean
 s e mail and password CMP fields,
they are both considered read only fields. Conversely, the implementation entity bean
must defined both getters and setter methods for the properties, even though the
properties are read only. This is covered in the next panel.
Defining CMP fields in the entity bean class
(implementation)
Unlike the local interface the implementation entity bean class must defined both
getters and setter methods for the CMP fields, even though the CMP fields are
read only. The getter and setter methods for the CMP fields are abstract methods since
there implementation will be defined by the EJB container. The code for the
implementation class is as follows:
package com.rickhightower.auth;
public abstract class UserBean implements EntityBean {
public abstract String getEmail();
Introducing EJB CMP/CMR, Part 1 of 2
Page 13 of 48






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

tomcat web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved