Tuesday, January 16, 2007

SCBCD - Entity Beans

1)Which method from the EntityContext interface, or indirectly the EJBContext interface returns the entity's bean remote home interface?
getEJBLocalObject
getEJBLocalHome
getEJBRemoteHome
getEJBHome
getEJBObject

2)
The ______ element of the deployment descriptor specifies the primary key class that maps to multiple fields in the entity bean class. [Fill in the name of the element without brackets]

3)
Which method of the javax.ejb.EntityContext interface, or indirectly the javax.ejb.EJBContext interface can be used to determine the entity bean's local home interface? (Enter the method name without the brackets) ______

4)
Which method from the EntityContext interface, or indirectly the EJBContext interface returns the entity's bean local home interface?
getEJBLocalObject
getEJBLocalHome
getEJBLocalInterface
getEJBLocalHomeObject
getEJBObject
5)Assume the following deployment descriptor code-snippet. Which of the following statements regarding primary keys are correct? [Select all correct answers]

<entity id="OrderIdGenerator">
<ejb-name>OrderIdGenerator</ejb-name>
<local-home>com.baboon.ejb.OrderIdGeneratorHome</local-home>
<local>com.baboon.ejb.OrderIdGenerator</local>
<ejb-class>com.baboon.ejb.OrderIdGeneratorBean</ejb-class>
<persistence-type>Container</persistence-type>

<prim-key-class>com.baboon.ejb.OrderIdGeneratorKey</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>OrderIdGenerator</abstract-schema-name>
<cmp-field>
<field-name>pKey</field-name>
</cmp-field>
<cmp-field>
<field-name>orderId</field-name>
</cmp-field>
</entity>

The primary key class, com.baboon.ejb.OrderIdGeneratorKey, must be public and contains a public constructor with the primary key field as argument.
The primary key class, com.baboon.ejb.OrderIdGeneratorKey, cannot be used in the deployment descriptor for CMP entity beans.
The element <primkey-field> is missing in the code-snippet.
The entity bean OrderIdGenerator will most likely make use of a compound key.
The Bean provider must specify the fully-qualified name of the Entity bean's primary key class in the <prim-key-class> element.

6)Consider the following OrderKey class, with primary key orderId, that represents the primary key class for the entity bean Order. Which of the following statements are correct? [Select all correct answers]
public class OrderKey implements java.io.Serializable {
private String orderId = null;
public OrderKey(java.lang.String orderId) {
this.orderId = orderId;
}
public boolean equals(java.lang.Object otherKey) {
return false;
}
public int hashCode() {
return (orderId.hashCode());
}
}
The primary key class OrderKey is a compound key class, at least 2 instance variables has to be defined to make up the primary key.
The primary key class OrderKey must define the orderId instance variable as public.
The primary key class OrderKey must define a public constructor with no parameters.
The primary key class OrderKey does not have getters and setters for the primary key field orderId.
The deployment descriptor has to define the element <primkey-field> for the instance variable orderId.

7)
Which method from the EntityContext interface, or indirectly the EJBContext interface returns the entity bean's remote interface?

getEJBRemoteHome
getEJBHome
getEJBObject
getEJBLocalHome
getEJBLocalObject

8)
Which method of the EntityContext interface can be used to return an entity bean's local interface?

getEJBLocalHome
getEJBLocalInterface
getEJBLocalObject
getEJBObject
getEJBLocalEntityObject

9)
Which method of the javax.ejb.EntityContext interface, or indirectly the javax.ejb.EJBContext interface can be used to return the entity bean's remote home interface? (Enter the method name without the brackets) ______

10)
The ______ element of the deployment descriptor specifies the container-managed field of the entity bean class that contains the primary key. [Fill in the name of the element without brackets]

Answers:

1)4

Answer 4 is correct.

The getEJBHome method, defined in the EJBContext interface, obtains the enterprise bean's remote home interface. This method returns an IllegalStateException when the enterprise bean does not have a remote home interface.

An enterprise Bean's remote home interface defines the methods that allow a remote client to create, find, and remove EJB objects, as well as home business methods that are not specific to a bean instance.

Answer 1 is incorrect, getEJBLocalObject returns the entity bean's local interface. Answer 2 is incorrect, getEJBLocalHome method returns the entity bean's local home interface. Answer 3 is incorrect, this method does not exist. Answer 5 is incorrect, getEJBObject method returns the entity bean's remote interface.


2)
The prim-key-class defines the primary key class that maps to multiple fields in the entity bean. 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. (This allows the container to extract the primary key fields from an instance's container-managed fields, and vice versa.)

3)
The correct answer is getEJBLocalHome. This method obtains the enterprise bean's local home interface. An enterprise bean's local home interface defines the methods that allow local clients to create, find, and remove EJB objects, as well as home business methods that are not specific to a bean instance.

4)2

Answer 2 is correct, getEJBLocalHome obtains the enterprise bean's local home interface.

Answer 1 is incorrect, getEJBLocalObject returns the entity bean's local interface. Answer 3 is incorrect, this method does not exist. Answer 4 is incorrect, getEJBLocalHomeObject method does not exists. Answer 5 is incorrect, getEJBObject returns the entity bean's remote interface.


5)4,5

Answers 4 and 5 are correct.

When specifying the element <prim-key-class> the fields must be a subset of the names of the container managed fields. The primary key class can contain 1 or more fields that act as the key for the entity bean. In this example the container managed fields are <code>pKey</code> and <code>orderId</code>. The primary key class can make use of both fields as the compound key or only 1 field. It is illegal to define only the name of the class that is the primary key class, it has to be the fully-qualified name.

Answer 1 is incorrect, the OrderIdGenereratorKey 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.

Answer 2 is incorrect. Container managed persistence entity beans can have a primary key class that maps to multiple fields in the entity bean class or can have a single field as primary key identified by the element <primkey-field> in the deployment descriptor.

Answer 3 is incorrect. The <primkey-field> is an optional element and is used to map a single field to a primary key.

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.

  2. Primary key that maps to multiple fields 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.

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. (This allows the container to extract the primary key fields from an instance's container-managed fields, and vice versa.)



6)2,3

Answers 2 and 3 are correct. The OrderKey class is a primary key class that is used for implementing compound keys. 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.

Answer 1 is incorrect. The primary key class will be used to identify the primary key for the underlying data source. A primary key can map to a single field or to many fields. However, when mapping to a single field, it is not necessary to define a primary key class.

Answer 4 is incorrect. There is no requirement to implement getters and setters in the primary key class. It is however possible to do so, but an java.lang.IllegalStateException will be thrown when you try to set the primary key field after it has been set in the ejbCreate<METHOD>(...).

Answer 5 is incorrect. The <primkey-field> element in the deployment descriptor is been used to map a single field to a primary key without a primary key class. The <prim-key-class> element is required to be part of the Order entity bean definition in the deployment descriptor.



7)3

Answer 3 is correct, getEJBObject returns the entity bean's remote interface.

A bean instance can use this method; for example, when it wants to pass a reference to itself in a method argument or result. Enterprise beans cannot return or use the this reference as an argument. The interaction with the bean must pass through the interposition class.

Answer 1 is incorrect, this method does not exist. Answer 2 is incorrect, getEJBHome returns the entity bean's remote home interface. Answer 4 is incorrect, getEJBLocalHome returns the entity bean's local home interface. Answer 5 is incorrect, getEJBLocalObject returns the entity bean's local interface.



8)3

Answer 3 is correct, getEJBLocalObject returns the entity bean's local interface.

Answer 1 is incorrect, getEJBLocalHome obtains the enterprise bean's local home interface. Answer 2 is incorrect, this method does not exist. Answer 4 is correct, etEJBObject returns the entity bean's remote interface. Answer 5 is incorrect, this method does not exist.



9)
The correct answer is getEJBHome. This method obtains the enterprise bean's remote home interface. An enterprise bean's remote home interface defines the methods that allow a remote client to create, find, and remove EJB objects, as well as home business methods that are not specific to a bean instance.

10)
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. The primkey-field is used to map a single field in the entity bean class.



No comments: