Identify the interfaces and methods a CMP entity bean must and must not implement.

The following are the requirements for an entity bean class:

The following are the requirements for a dependent value class:

The entity bean class MUST implement the ejbCreate<METHOD>(...) methods that correspond to the create<METHOD>(...) methods specified in the entity bean’s home interface.

The entity bean class may define ZERO or more ejbCreate<METHOD>(...) methods whose signatures must follow these rules:

For each ejbCreate<METHOD>(...) method, the entity bean class MUST define a matching ejbPostCreate<METHOD>(...) method, using the following rules:

The entity bean class may define ZERO or more HOME methods whose signatures must follow the following rules:

The entity bean class may define one or more SELECT methods whose signatures must follow the following rules:

The entity bean class may define ZERO or more BUSINESS methods whose signatures must follow these rules:

public abstract class AddressBean implements javax.ejb.EntityBean {
	...
	public Integer ejbCreateAddress(String street, String city, 
			String state,  String zip) throws CreateException   {
		setId(..);
		setStreet(..);
		setCity(..);
		...
		return null; // for CMP 2.x !!!
	}

	public void ejbPostCreateAddress(String street, String city,
		String state,  String zip) {  
	}

	// persistent fields
	public abstract Integer getId();
	public abstract void setId(Integer id);
	public abstract String getStreet();
	public abstract void setStreet(String street);
	public abstract String getCity();
	public abstract void setCity(String city);

	// ejbSelect methods
	public abstract Collection ejbSelectZipCodes(String state)
		throws FinderException;

	public abstract Collection ejbSelectAll()
		throws FinderException;

	public abstract CustomerLocal ejbSelectCustomer(AddressLocal addr)
		throws FinderException;

	// customer home methods.  These are wrappers of ejbSelect methods
	public Collection ejbHomeQueryZipCodes(String state)
			throws FinderException   {
		return ejbSelectZipCodes(state);
	}

	public Collection ejbHomeQueryAll()
			throws FinderException   {
		return ejbSelectAll();
	}

	public CustomerLocal ejbHomeQueryCustomer(AddressLocal addr)
			throws FinderException   {
		return ejbSelectCustomer(addr);
	}

	// standard call back methods
	public void setEntityContext(EntityContext ec){}
	public void unsetEntityContext(){}
	public void ejbLoad(){}
	public void ejbStore(){}
	public void ejbActivate(){}
	public void ejbPassivate(){}
	public void ejbRemove(){}
}
					
					
<entity>
	<ejb-name>AddressEJB</ejb-name>
	...
	<prim-key-class>java.lang.Integer</prim-key-class>
	<reentrant>False</reentrant>
	<cmp-version>2.x</cmp-version>
	<abstract-schema-name>Address</abstract-schema-name> 
	<cmp-field><field-name>id</field-name></cmp-field>
	<cmp-field><field-name>street</field-name></cmp-field>
	...
	<primkey-field>id</primkey-field>
	<security-identity><use-caller-identity/></security-identity>
	<query>
		<query-method>
			<method-name>ejbSelectZipCodes</method-name>
			<method-params>
				<method-param>java.lang.String</method-param>
			</method-params>
		</query-method>
		<ejb-ql>
			SELECT a.zip FROM Address AS a
			WHERE a.state = ?1
		</ejb-ql>
	</query>
	<query>
		<query-method>
			<method-name>ejbSelectAll</method-name>
			<method-params/>
		</query-method>
		<ejb-ql>
			SELECT OBJECT(a) FROM Address AS a
		</ejb-ql>
	</query>
	...   
</entity>
					
					

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine