Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.

This page discusses - Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.

Ads

Tutorials   
Chapter 5. Client View of an Entity Identify correct and incorrect statements about the Application Assembler's responsibilities, including the use of deployment descriptor elements related to transactions and the identifica Given a list of responsibilities, identify whose which are the Container's with respect to transactions, including the handling of getRollbackOnly, setRollbackOnly, getUserTransacti EJB Transactional Attributes Chapter 11. Transactions Given a list of scenarios, identify which will result in an ejbRemove method not being called on a bean instance. Given a list of responsibilities related to session beans, identify those which are the responsibility of the session bean provider and those which are the responsibility of the EJB contai Given a list of methods for a stateful or stateless session bean class, define which of the following operations can be performed from each of those methods: SessionContext interface metho Chapter 4. Session Bean Life Cycle Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces. Identify the interface and method for each of the following: retrieve the session bean's remote home interface, retrieve the session bean's local component interface, determine if the sessio Match the correct description about purpose and function to which session bean type they apply: stateless, stateful, or both. Chapter 14. Security Management Given a security-related deployment descriptor tag, identify correct and incorrect statements and code related to that tag. Given a list of responsibilities, identify which belong to the deployer, bean provider, application assembler, container provider, system administrator, or any combination. From a list of responsibilities, identify which belong to the application assembler, bean provider, deployer, container provider, or system administrator. Part I. Exam Objectives Preface Identify the interfaces and methods a JMS message-driven bean must implement. Identify the use and behavior of the MessageDrivenContext interface methods. SCBCD Study Guide Given a list of responsibilities related to exceptions, identify those which are the bean provider's, and those which are the responsibility of the container provider. Be prepared to recog Given a particular method condition, identify the following: whether an exception will be thrown, the type of exception thrown, the container's action, and the client's view. Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans, and message-driven beans. Identify correct and incorrect statements or examples about the client's view of exceptions received from an enterprise bean invocation. Identify correct and incorrect statements or examples about an entity bean's primary key and object identity. Identify the use, syntax, and behavior of, the following entity bean home method types, for Container-Managed Persistence (CMP); finder methods, create methods, remove methods, and home me Chapter 8. Entity Beans Chapter 13. Enterprise Bean Environment Chapter 2. Client View of a Session Bean Match EJB roles with the corresponding description of the role's responsibilities, where the description may include deployment descriptor information. Given a list, identify which are requirements for an EJB-jar file. Identify correct and incorrect statements or examples about the client view of a entity bean's remote component interface (EJBObject). Identify correct and incorrect conditional expressions, BETWEEN expressions, IN expressions, LIKE expressions, and comparison expressions. Identify correct and incorrect statements or examples about the purpose and use of EJB QL. Chapter 9. EJB-QL Identify correct and incorrect statements or examples about EJB programming restrictions. Chapter 1. EJB Overview Identify EJB 2.0 container requirements. Identify correct and incorrect statements or examples about the client view of an entity bean's local component interface (EJBLocalObject). Chapter 12. Exceptions Identify the use and the behavior of the ejbPassivate method in a session bean, including the responsibilities of both the container and the bean provider. Identify correct and incorrect statements about the purpose and use of the deployment descriptor elements for environment entries, EJB references, and resource manager connection factory r Chapter 10. Message-Driven Bean Component Contract Given a code listing, determine whether it is a legal and appropriate way to programmatically access a caller's security context. From a list, identify the responsibility of the container for a CMP entity bean, including but not limited to: setEntityContext, unsetEntityContext, ejbCreate, ejbPostCreate, ejbActi Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP bean. Chapter 7. CMP Entity Bean Life Cycle From a list, identify the purpose, behavior, and responsibilities of the bean provider for a CMP entity bean, including but not limited to: setEntityContext, unsetEntityContext, ejbC Identify correctly-implemented deployment descriptor elements for a CMP bean (including container-managed relationships).
Ads

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>(...) 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>(...) 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:

  1. Primary key that maps to a SINGLE field in the entity bean class.

    The Bean Provider uses the primkey-field element of the deployment descriptor to specify the container-managed field of the entity bean class that contains the primary key. The field’s type must be the primary key type.

    								
    <entity>
    	<ejb-name>CabinEJB</ejb-name>
    	<home>com.titan.cabin.CabinHomeRemote</home>
    	<remote>com.titan.cabin.CabinRemote</remote>
    	<ejb-class>com.titan.cabin.CabinBean</ejb-class>
    	<persistence-type>Container</persistence-type>
    	<prim-key-class>java.lang.Integer</prim-key-class>
    	<reentrant>False</reentrant>
    	<cmp-version>2.x</cmp-version>
    	<abstract-schema-name>Cabin</abstract-schema-name>
    	<cmp-field><field-name>id</field-name></cmp-field>
    	<cmp-field><field-name>name</field-name></cmp-field>
    	<cmp-field><field-name>deckLevel</field-name></cmp-field>
    	<cmp-field><field-name>shipId</field-name></cmp-field>
    	<cmp-field><field-name>bedCount</field-name></cmp-field>
    	<primkey-field>id</primkey-field>
    	<security-identity><use-caller-identity/></security-identity>
    </entity>
    								
    								
  2. Primary key that maps to MULTIPLE fields in the entity bean class.

    The primary key class MUST be public, and MUST have a public constructor with NO PARAMETERS.

    ALL fields in the primary key class MUST be declared as public.

    The names of the fields in the primary key class MUST be a subset of the names of the container-managed fields.

public class ItemKey implements java.io.Serializable {
	public String productId; // public - mandatory
	public String vendorId; // public - mandatory
	public ItemKey() { }; // no-args constructor - mandatory
	
	public ItemKey(String productId, String vendorId) {
		this.productId = productId;
		this.vendorId = vendorId;
	}
	
	public String getProductId() {
		return productId;
	}

	public String getVendorId() {
		return vendorId;
	}
	
	public boolean equals(Object other) { // mandatory
		if (other instanceof ItemKey) {
			return (productId.equals(((ItemKey)other).productId) 
			&& vendorId.equals(((ItemKey)other).vendorId));
		}
		return false;
	}

	public int hashCode() { // mandatory
		return productId.hashCode();
	}
}
					
A primary key class MUST meet these requirements:
  • The access control modifier of the class is public.

  • All fields are declared as public.

  • Field names in the primary key clsss MUST match the corresponding container-managed fields in the entity bean class.

  • The class has a public default (no-args) constructor.

  • The class implements the hashCode() and equals(Object obj) methods.

  • The class is SERIALIZABLE (implements java.io.Serializable).

In special situations, the entity Bean Provider may choose not to specify the primary key class or the primary key fields for an entity bean with container-managed persistence. This case usually happens when the entity bean does not have a natural primary key, and/or the Bean Provider wants to allow the Deployer using the Container Provider’s tools to select the primary key fields at deployment time. The entity bean’s primary key type will usually be derived from the primary key type used by the underlying database system that stores the entity objects. The primary key used by the database system may not be known to the Bean Provider.

In this special case, entity bean must meet these requirements:

  • In the deployment descriptor, the primary key class is defined (by Bean Provider) as a java.lang.Object. The primary key field is not specified.

  • In the HOME interface, the argument of the findByPrimaryKey method MUST be a java.lang.Object.

  • In the entity bean CLASS, the return type of the ejbCreate method MUST be a java.lang.Object.

We are using 2 elements in DD for defining primary keys: <prim-key-class> and <primkey-field> :

  • SINGLE-FIELD primary key: <prim-key-class> is a MANDATORY, <primkey-field> is a MANDATORY.

  • COMPOUND primary key: <prim-key-class> is a MANDATORY, <primkey-field> MUST NOT be defined.

The primary key class can be specific to a particular entity bean class. That is, each entity bean can define its own primary key class. Or multiple entity beans CAN share the same primary key class.

If two entity objects with the SAME home interface have the SAME primary key, they are considered IDENTICAL entity objects. If they have a different primary key, they are considered different entity objects.

There are 2 ways of comparing Entity Beans:

  1. Using isIdentical(EJBObject obj) method of javax.ejb.EJBObject interface on bean's REMOTE interface, or isIdentical(EJBLocalObject obj) method of javax.ejb.EJBLocalObject interface on bean's LOCAL interface.

    Item item1 = ...;
    Item item2 = ...;
    
    if (item1.isIdentical(item2)) {
    	// item1 and item2 refer to the same entity object
    }
    							
  2. Comparing primary keys of two entity object references (ONLY FROM THE SAME HOME INTERFACE !).

    ItemHome itemHome = ...; // get home interface
    Item item1 = itemHome.findByName(...);
    Item item2 = itemHome.findByCountry(...);
    
    if (item1.getPrimaryKey().equals(item2.getPrimaryKey())) {
    	// item1 and item2 refer to the same entity object
    }
    							

Advertisements

Share on Google+Share on Google+

Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.

Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads