TECHNICALFACILITATION.COM - THE ULTIMATE WEBSPHERE AND JAVA CERTIFICATION GUIDES AND RESOURCES
Google
Download the Completed Solution: 12bmpbeans.ear.

Scroll to the bottom of the page for pertinent code snippets.

Creating a Very Helpful Bean Managed Persistence (BMP) Entity Bean

This free, multimedia tutorial shows you how to use IBM's Rational Application Developer (IRAD) 6.0 to create a very simple Bean Managed Persistence Entity Bean (BMP). Now, we don't actually get into JDBC here. The focus is on how a BMP works, and how the EJB container calls the various methods of a BMP to ensure that an application always have the latest and greatest data from the database.

You'll be surprised. Even though we don't don any database access in this tutorial, it'll probably teach you more about BMPs than any other BMP or entity bean tutorial you've ever seen.

If you found something helpful here, please do your part and help support the site. Link to us, buy some books, support our sponsors, tell your developer friends about us, and remember: Happy Java!

package com.examscam.ejb;
/**
* Bean implementation class for Enterprise Bean: PersonBMP
*/
public class PersonBMPBean implements javax.ejb.EntityBean {

String name;
int age;



/**
* @return Returns the age.
*/
public int getAge() {
System.out.println("In getAge");
return age;
}
/**
* @param age The age to set.
*/
public void setAge(int age) {
System.out.println("In setAge");
this.age = age;
}
/**
* @return Returns the name.
*/
public String getName() {
System.out.println("In getName");
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
System.out.println("In setName");
this.name = name;
}
private javax.ejb.EntityContext myEntityCtx;
/**
* ejbActivate
*/
public void ejbActivate() {
System.out.println("In ejbActivate");
}
/**
* ejbLoad
*/
public void ejbLoad() {
System.out.println("In ejbLoad");
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
System.out.println("In ejbPassivate");
}
/**
* ejbRemove
*/
public void ejbRemove() throws javax.ejb.RemoveException {
System.out.println("In ejbRemove");
}
/**
* ejbStore
*/
public void ejbStore() {
System.out.println("In ejbStore");
}
/**
* getEntityContext
*/
public javax.ejb.EntityContext getEntityContext() {
System.out.println("In getEntityContext");
return myEntityCtx;
}
/**
* setEntityContext
*/
public void setEntityContext(javax.ejb.EntityContext ctx) {
System.out.println("In setEntityContext");
myEntityCtx = ctx;
}
/**
* unsetEntityContext
*/
public void unsetEntityContext() {
System.out.println("In unsetEntityContext");
myEntityCtx = null;
}
/**
* ejbCreate
*/
public com.examscam.ejb.PersonBMPKey ejbCreate()

throws javax.ejb.CreateException {
System.out.println("In ejbCreate");
return null;
}
/**
* ejbPostCreate
*/
public void ejbPostCreate() throws javax.ejb.CreateException {
System.out.println("In ejbPostCreate");
}
/**
* ejbFindByPrimaryKey
*/
public com.examscam.ejb.PersonBMPKey ejbFindByPrimaryKey(
com.examscam.ejb.PersonBMPKey primaryKey)
throws javax.ejb.FinderException {
System.out.println("In findBy");
return null;
}
}

package com.examscam.ejb;
/**
* Local Home interface for Enterprise Bean: PersonBMP
*/
public interface PersonBMPLocalHome extends javax.ejb.EJBLocalHome {
/**
* Creates an instance from a key for Entity Bean: PersonBMP
*/
public com.examscam.ejb.PersonBMPLocal create()
throws javax.ejb.CreateException;
/**
* Finds an instance using a key for Entity Bean: PersonBMP
*/
public com.examscam.ejb.PersonBMPLocal findByPrimaryKey(
com.examscam.ejb.PersonBMPKey primaryKey)
throws javax.ejb.FinderException;
}
package com.examscam.ejb;
/**
* Local interface for Enterprise Bean: PersonBMP
*/
public interface PersonBMPLocal extends javax.ejb.EJBLocalObject {
/**
* @return Returns the age.
*/
public int getAge();
/**
* @param age The age to set.
*/
public void setAge(int age);
/**
* @return Returns the name.
*/
public String getName();
/**
* @param name The name to set.
*/
public void setName(String name);
}
package com.examscam.ejb;
/**
* Key class for Entity Bean: PersonBMP
*/
public class PersonBMPKey implements java.io.Serializable {
static final long serialVersionUID = 3206093459760846163L;
/**
* Creates an empty key for Entity Bean: PersonBMP
*/
public PersonBMPKey() {
}
/**
* Returns true if both keys are equal.
*/
public boolean equals(java.lang.Object otherKey) {
if (otherKey instanceof com.examscam.ejb.PersonBMPKey) {
com.examscam.ejb.PersonBMPKey o = (com.examscam.ejb.PersonBMPKey) otherKey;
return (super.equals(otherKey));
}
return false;
}
/**
* Returns the hash code for the key.
*/
public int hashCode() {
return (super.hashCode());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>
ExamScamEJB</display-name>
<enterprise-beans>
<session id="StatefulTimer">
<ejb-name>StatefulTimer</ejb-name>
<home>com.examscam.ejb.StatefulTimerHome</home>
<remote>com.examscam.ejb.StatefulTimerRemote</remote>
<ejb-class>com.examscam.ejb.StatefulTimerBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
<session id="StatelessTimer">
<ejb-name>StatelessTimer</ejb-name>
<home>com.examscam.ejb.StatelessTimerHome</home>
<remote>com.examscam.ejb.StatelessTimerRemote</remote>
<ejb-class>com.examscam.ejb.StatelessTimerBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<entity id="PersonBMP">
<ejb-name>PersonBMP</ejb-name>
<local-home>com.examscam.ejb.PersonBMPLocalHome</local-home>
<local>com.examscam.ejb.PersonBMPLocal</local>
<ejb-class>com.examscam.ejb.PersonBMPBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>com.examscam.ejb.PersonBMPKey</prim-key-class>
<reentrant>false</reentrant>
</entity>

</enterprise-beans>
<ejb-client-jar>ExamScamEJBClient.jar</ejb-client-jar>
</ejb-jar>
Google
THE ULTIMATE CERTIFICATION AND WEBSPHERE RESOURCES - BUY THEM NOW ON AMAZON
eXTReMe Tracker