Friday, March 02, 2007

JAVA 認證心得 -- SCBCD (5)

CMP Entity Bean Lifecycle
##CONTINUE##

  • The ejbStore method in CMP entity beans is invoked before the instance's persistent state is synchronized.
  • The ejbLoad method in CMP entity beans is invoked after the instance's persistent state is loaded from the persistent store
  • The container associates appropriate EntityContext to the bean before calling any other method. This entity context contains the primary key information for the entity bean. This information can be retrieved using the getPrimaryKey() method of EntityContext interface.
  • Every <ejb-relation> element has two <ejb-relation-role> elements.
  • The implementation of the Bean Provider’s ejbCreate<METHOD> methods of a CMP entity bean should always return null, even though the method is declared to return the primary key type
  • Each ejbSelect method must have a corresponding <query> element specified in the deployment descriptor
  • The ejbSelect methods can return container-managed relationship and persistent fields and a entity bean's component interface or its collection
  • The Bean Provider is responsible for providing the implementation of ejbHome methods in entity beans with container-managed persistence
  • An entity bean class may declare 0 or more ejbHome methods that must be prefixed with “ejbHome”. Must be public, it must not contain the static modifier. Its arguments and return values must be legal RMI-IIOP types. Its throws cluse may contain arbitrary application exceptions ,but not the java.rmi.RemoteException.
  • ejbCreate sets primary key fields. ejbPostCreate sets bean relationship fields. ejbHome[method] Used to implement methods that do not require a bean identity.
  • <cmp-field> <field-name>age</field-name> </cmp-field>
  • It is possible for an Entity Bean not to have any create methods.
  • As per EJB Specification 2.0 10.3.8 (Page 155) It is the responsibility of the Container to raise the java.lang.IllegalArgumentException if the Bean Provider attempts to assign null as the value of a collection-valued cmr-field by means of the set accessor method.
  • A client program must use the PortableRemoteObject. narrow(...) method to convert the objects contained in the collections returned by a finder method on the entity bean's remote home interface to the end
    Collection students = theHome.findByName("john"); Student first = (Student) PortableRemoteObject.narrow(students.get(0), Student.class);
  • findByPrimaryKey is the method that must always be declared in the (local or remote) home interface of an entity bean.
  • If a finder method is defined to return a single entity object (i.e object implementing entity bean's component interface) and the corresponding query deployment descriptor element results in returning multiple entity objects (i.e objects implementing entity bean's component interface) then the container throws javax.ejb.FinderException.
  • In ejbActivate() method Bean Provider cannot use set accessor methods for abstract persistence schema to initialize the container-managed relationship or persistent fields.
  • A cascade-delete enabled bean is automatically removed when any “multiplicity of one” bean with which it is related is removed.

Read more!

No comments: