|
Page 1 of 2
SCBCD Study Notes : Chapter 8 : Entity Beans
Please find the Study Notes and resources which covers Chapter 8 : Entity Beans, as part of the Sun Certified Business Component Developer exam CX-310-090.
- From a list of behaviors, match them with the appropriate EntityContext method responsible for that behavior.
- Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.
Chapter 8 : Entity Beans
From a list of behaviors, match them with the appropriate EntityContext method responsible for that behavior.
From a list of behaviors, match them with the appropriate EntityContext method responsible for that behavior.
A CONTAINER provides the entity bean instances with an EntityContext, which gives the entity bean instance access to the instance’s context maintained by the container. The EntityContext interface has the following methods:
- The getEJBObject method returns the entity bean’s REMOTE [component] interface.
.
- The getEJBHome method returns the entity bean’s REMOTE HOME interface.
.
- The getEJBLocalObject method returns the entity bean’s LOCAL [component] interface.
.
- The getEJBLocalHome method returns the entity bean’s LOCAL HOME interface.
.
- The getCallerPrincipal method returns the java.security.Principal that identifies the invoker of the bean instance’s EJB object.
.
- The isCallerInRole method tests if the entity bean instance’s caller has a particular role.
.
- The setRollbackOnly method allows the instance to mark the current transaction such that the only outcome of the transaction is a rollback (EntityBeans support ONLY CMT).
.
- The getRollbackOnly method allows the instance to test if the current transaction has been marked for rollback. (EntityBeans support ONLY CMT).
.
- The getPrimaryKey method returns the entity bean’s primary key.
.
- The getUserTransaction method returns the javax.transaction.UserTransaction interface. Entity bean instances MUST NOT call this method. It is derived from EJBContext interface, which is parent for contexts for all 3 types of EJB, but it is used ONLY with BMT in Session Beans and Messages Driven Beans.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
public interface EntityContext extends EJBContext { ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;EJBLocalObject getEJBLocalObject() throws IllegalStateException; ;;;;;;
;;;;;;;EJBObject getEJBObject() throws IllegalStateException; ;;;;;;;;;;;;;;;;
;;;;;;;Object getPrimaryKey() throws IllegalStateException; ;;;;;;;;;;;;;;;;;;
} ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
public interface EJBContext { ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;EJBHome getEJBHome(); ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;EJBLocalHome getEJBLocalHome(); ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;Principal getCallerPrincipal(); ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;boolean isCallerInRole(String roleName); ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;UserTransaction getUserTransaction() throws IllegalStateException; ;;;;
;;;;;;;void setRollbackOnly() throws IllegalStateException; ;;;;;;;;;;;;;;;;;;
;;;;;;;boolean getRollbackOnly() throws IllegalStateException;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.
From the viewpoint of the Bean Provider, entity objects have a runtime object identity that is maintained by the Container.
The Container maintains the persistent identity of an entity object on the basis of its PRIMARY KEY.
The primary key of an entity bean may or may not be visible as one or more cmp-fields of the instance, depending on the way in which it is specified. Once it has been set, the Bean Provider MUST NOT attempt to change the value of a primary key field by means of a set method on its cmp-fields.
When a new instance of an entity bean whose primary key fields are visible in the entity bean class is created, the Bean Provider MUST use the ejbCreate(...) method to set all the primary key fields of the entity bean instance before the instance can participate in a relationship, e.g. be used in a set accessor method for a cmr-field. The Bean Provider MUST NOT reset a primary key value by means of a set method on any of its cmp-fields after it has been set in the ejbCreate(...) method.
The container must be able to manipulate the primary key type of an entity bean. Therefore, the primary key type for an entity bean with container-managed persistence MUST follow the rules:
- The Bean Provider MUST specify a primary key class in the deployment descriptor. (In case the class is not known until deployment, Bean Provider specify java.lang.Object class).
.
- The primary key type MUST be a legal Value Type in RMI-IIOP (serializable).
.
- The class MUST provide suitable implementation of the hashCode() and equals(Object obj) methods to simplify the management of the primary keys by the Container.
There are two ways to specify a primary key class for an entity bean with container-managed persistence:
|