Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Section 5. Example 1: Finder and Create methods
The Create method
Thus, far I havecovered defining the CMP fields. Another key feature CMP 2.0 defines
your
findByPrimaryKey()
method. Notice that
ejbFindByPrimaryKey()
is
absent from the entity bean class as it is defined by the EJB container. The finder
method,
findByPrimaryKey()
must be declared in the home interface (listed
below).
Lastly, lets cover the ability to create UserBeans. The
UserBean
entity class defines
two create methods.
ejbCreate()
and
ejbPostCreate()
. Since the e mail and
password CMP fields are read only (you don t have setter methods for e mail and
password CMP fields in the local interface), it is prudent to allow them to be initialized
using the
ejbCreate()
method as shown below.
package com.rickhightower.auth;
public abstract class UserBean implements EntityBean {
public String ejbCreate(String email, String password)
throws CreateException {
setEmail(email);
setPassword(password);
return null;
}
public void ejbPostCreate(String email, String password) { }
}
The Create method
One thing that you will notice is that the implementation of these methods is virtually
empty. Also notice, that the setEmail, setPassword methods that the
ejbCreate()
method calls are abstract; thus, they are defined by the EJB container during
deployment.
Remember that the
ejbCreate()
method gets called before the container inserts the
row into the database and the
ejbPostCreate()
gets called after the container
inserts the row into the database. Since the container, manages the creation of the
entity bean, the
ejbCreate()
method returns
null
. The corresponding create method
Introducing EJB CMP/CMR, Part 1 of 2
Page 17 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