EJB 2.0 Entity Model

Explain the advantages of EJB 2.0 container-managed persistence over bean-managed persistence.

- The main advantage of CMP over BMP is that with CMP, is the developers hardly need to author the code for data access. Considering less code implies very less chances of getting wrong results and supporting less problems if there are multiple databases.

- The sorting mechanism is not supported in EJB QL. Reason is EJB QL does not support ORDER BY clause. The sorting can be done after retrieving data and can be simplified by using the Java collections framework (sort() method ).

- To be simple and clear, the CMP is being performed by the container which needs almost no hard coding.

- While implementing the beans the complexity is reduced and all the finder methods are implemented by the container.

Explain the types and role of abstract methods in EJB 2.0 persistence.

- In EJB 2.0 a CMP bean is defined as abstract. The CMPs persistence fields are not directly defined in the bean class.

- Instead, a schema named ‘abstracted persistent schema’ has developed. This schema lets the bean provider declare the relationships and the persistent fields indirectly.

- The deployment descriptor contains the container-managed fields and relationships declared in the abstract persistence schema.

- The logic for the BMP beans that access the database based on object-to-relational mapping information is provided by the bean developer.

- The following are two declarations of the inheritance hierarchy of a bean class:

1. Bean Developer’s Abstract Class implements javax.ejb.EntityBean.

2. Persistence Manager’s Concrete Bean Class extends Bean Developer’s Abstract Class.

Explain the structure of EJB query language (EJB QL)

Structure of EJB QL:

- The EJB QL structure comprises of the following:

1. SELECT clause:

- SELECT clause returns the values to the EJB QL. The value can be an entity bean, attribute or a simple java object.

2. FROM clause:

- FROM clause specifies the scope of the query. The scope is a the identification variables.

- In order to a valid query every query must contain the FROM clause. There are two components in the FROM clause :

FROM {AbstractSchemaName entityBeanVariable}
AbstractSchemaName is the specification of an alias name for an entity bean using the tag <abstract-schema-name> in the ejb-jar.xml file.

Using IN : The IN keyword designate a set of data collection for the preceding identifier to evaluate.
Using AND: The AND clause is used to combine logical expressions in the query.
Using AS: The AS clause is used to designate an identifier as the rest of the query.

3. WHERE clause:

- WHERE clause specifies the conditional selection for the query which results in restricted values in the query. This clause is optional.

Explain the role that callbacks play in developing Entity beans with container-managed persistence.

- The following are EJB callbacks along with pros and cons:

Magic callbacks :

- The container defined method is same.

- For example:
public void ejbPassivate();
- Template code, base class, interface dependency are not available and very lightweight. Won’t express the container dependency and easily breakable such as the typos by the developers.

Interface :

- The expression is clearly depended and no breakages.

- Coding template is a lot.

Base class :

- Template code availability in base class. Extendibility by the developers.

- No template code, not breakable.

- Single inheritance in java makes this base class.

Annotations :

- Method annotations as callback.

- Non code template , not breakable (annotations can be supported in IDE/compile), any name.

EntityManager callbacks as opposed to POJO callbacks.

- Absence of POJO class interference.

- Well-known event listener process exploitation.

- Very lightweight only called if specific class/life cycle event happens.

- Can be "aspect oriented".

- Absence of object-orientation.

Explain the use of local interfaces while modeling business objects.

- Local interfaces are communication interfaces, that are used between all the same machine resident EJBs.

- Remote methods overhead will be eliminated that is needed at the time of existence of EJBs in different clients and servers.

Local interfaces versus Dependent value objects.

Local interfaces:

- An interface that establishes the communications between EJBs of the same machine.

- The overhead of using remote methods can be eliminated by remote methods that are needed when the EJBs of separate clients and servers.

- Local interfaces are BMP constructs.

Dependent value objects:

- Dependent value objects leverage CMP constructs.

- Dependent value objects are persistent objects whose life cycle is managed by an entity bean.

- The assignment of a dependent value is done by set accessor method that copies to the target cmp-field.

- The serialization of the dependent value class is mandatory.

- The structure is not described in the deployment descriptor.

Explain the use of EJB query language.

- EJB query language is used to perform the database operations using finder and select methods of entity beans.

- The EJB QL, is used to define queries for CMP beans.

- The Bean Provider specifies the finder methods by the EJB QL in a portable way.

- The responsibility for the execution of finder queries that are need to be shifted to the native query language facilities which the persistent store, RDBMS provides.

- The queries for the finder and select methods of entity beans are defined by EJB Query Language with Container-Managed Persistence of entity beans.

- EJB QL queries find data using the "abstract schema" of the enterprise beans in your application.

What are the callback methods in Entity beans?

- In order to notify the events of a bean in the lifecycle, a bean class implements a set of methods, called callback methods.

- The entity bean implements the callback methods which are defined in the javax.ejb.EntityBean interface of EJB API.

- These methods are as follows:

public void setEntityContext() :

- It provides the bean with an interface to the EntityContext container.

- The EntityContext interface is used to obtain security information about the caller, to determine the status of the transaction or to force the transaction to rollback.

unsetEntityContext() :

- Used at the end of the life cycle of the bean and before the instance is evicted from the memory in order to perform the last minute clean-up.

ejbStore() and ejbUnload() :

- To know the entity bean’s state at the time synchronizing with the database.

ejbPassivate() and ejbActivate() :

- These both methods are invoked for the bean by the container just before the bean is passivated and after bean is activated respectively.

- Passivation specifies that the disassociation of the bean instance with its remote reference, so that the container evict it from memory or reuse it ejbRemove(); will be invoked just before the bean destroys the bean’s instance.
EJB Asynchronous communication
EJB Asynchronous communication - What is a message-driven bean?, Explain the need for asynchronous communication, What is the JMS messaging?, Explain the JavaMail API. Explain how it is used to compose and dispatch a mail.
EJB environment
EJB environment - What is the Enterprise Bean Environment?, Explain the EJB environment Entries, Explain the steps involved in accessing one enterprise bean from other.
EJB Resource Manager
EJB Resource Manager - What is a Resource Manager Connection factory?, Explain the five types of resource manager that J2EE compliant application server must support.
Post your comment