EJB types

Explain different types of EJB – Session beans, Entity beans and Message-driven beans.

Session Bean:

- The client’s business logic is implemented by a session bean of EJB.

- For example a session bean can calculate interest on deposits for a banking application.

- Session beans are used as reusable components in EJB architecture that encapsulate the business logic and can be used by other clients. These clients can optimize the use of EJB container.

- The name is derived as they are live as long as a client’s session using them.

Entity Bean:

- It is a data component that persists data onto a secondary storage such as a database.

- Like a simple java class, the Entity Bean has attributes and methods. Attributes are used to store data and methods are to perform operations on the fields.

- Entity beans can be viewed as a record in a database. An Entity Bean lasts as long as the data it represents.

Message-Driven Bean:

- A Message-Driven Bean is an enterprise bean that is used to manage messages asynchronously. It acts as a listener to receive messages.

- The message can be sent by using any J2EE component-application client, another enterprise bean, a web component or by a JMS application.

- Clients do not access the message driven beans through interfaces.

- Message Driven Beans are primarily focused on JMS.

- It is possible to get messages by multiple parties.

Explain types of session beans – stateless, stateful.

Stateless session bean :

- The stateless session bean does not hold a conversational state of the client.

- When a client invokes a method of this bean, the bean’s instance variables may contain a state, but only for the invocation period.

- When the method execution is completed, the state will be lost.

Stateful session bean :

- Stateful session bean is associated with a single client.

- The EJB container always uses the same stateful session bean instance to service a given client.

- The stateful session bean retains the data retrieved by the client from the database.

Explain types of Entity beans – Container-managed persistence (CMP) and Bean-managed persistence (BMP).

Container-Managed Persistence:

- When the entity object represents the persistence services, the Container-Managed Persistence (CMP) occurs.

- The persistence state of the bean is transparently and implicitly managed by the EJB container with the CMP.

- There is no deed to hardcode in order to access the database within the enterprise bean class.

Bean-Managed Persistence:

- Compared to CMP, Bean-Managed Persistence is complicated.

- The reason behind is to hardcode to persistence logic in the bean class.

- In order to hardcode the persistence logic, the enterprise developer need to know the type of database and also the way of the bean class fields maps to that of the database.

- BMP provides more flexibility in managing the state between bean class fields to the database.

What is the relationship between local interfaces and container-managed relationships?

- In case of Container-Managed Relationship is the target of an entity bean, there is a mandatory need of local interfaces.

- The direction of the relationship determines the target of a bean.

- The relationships can be one-to-one, one-to-many and many to many.

- The EJB container capable of managing these relationships with the help of referential integrity.

- These relationships are defined between local interfaces, which means a relationship cannot be created between two entities in separate applications, even in the same application server.

- The Container-Managed Relationship must reside in the same EJB JAR file because the access / interface to the beans is local.

- With this locality, increased performance is an advantage, because the access to local calls is faster that the remote calls.

When should I adopt BMP and when I should use CMP?

Adopting BMP:

- BMP should be used when the associations are complex between database tables.

- BMP is very useful when the entity beans require the synchronization with flat files.

- BMP would only be the right way, if entity beans synchronization is applied to multiple types of stores.

Adopting CMP:

- CMP can be used in order to support only relational database.

- CMP is used when there is a need of special-beans, such as multi-tables, which cannot be completely realized with a single bean.

- Apart from the normal persistence, where the performance is an issue, use CMP instead of BMP.
EJB roles
EJB roles - Describe the roles of EJB specification that are involved in the development and deployment of EJB application
EJB advantages and limitations
EJB advantages and limitations - Advantages of EJB model and limitations pf EJB models
EJB session beans
EJB session beans - What are the session beans? Explain the types of session beans, What are the steps involved in developing a stateless session bean?, Describe the lifecycle of stateless session beans, What are the steps involve in developing a stateful session beans, Describe the lifecycle of stateful session beans.
Post your comment