Monday, 14 September 2015

Java Source World: Enterprise beans

Enterprise beans | Java Source World


                                                                                               Java Source World          A Java quick reference blog

 Enterprise beans:




What are the different kinds of enterprise beans

Session Bean: is a non-persistent object that implements some business logic running on the server. Session beans do not survive system shut down. There are two types of session beans
  • Stateless session beans (each session bean can be reused by multiple EJB clients)
  •  Stateful session beans (each session bean is associated with one EJB client)


Entity Bean: is a persistent object that represents object views of the data, usually a row in a database.

 They have the primary key as a unique identifier. Multiple EJB clients can share each entity bean.  Entity beans can survive system shut shutdowns. Entity beans can have two types of persistence
  •  Container-managed persistence (CMP) - The container is responsible for saving the bean’s     state.
  •  Bean-managed persistence (BMP) – The Entity Bean is responsible for saving its own state.


Message-driven Bean: is integrated with the Java Message Service (JMS) to provide the ability to act as a message consumer and perform asynchronous processing between the server and the message producer.



What is the difference between session and entity beans?

Session Beans
Entity Beans
Use session beans for application logic.
Use entity beans to develop persistent object model.
Expect little reuse of session beans.
Insist on reuse of entity beans.
Session beans control the workflow and transactions of a
group of entity beans.
Domain objects with a unique identity (ie-primary key) shared by multiple clients.
Life is limited to the life of a particular client. Handle
database access for a particular client.
Persist across multiple invocations. Handles database access for multiple clients.
Do not survive system shut downs or server crashes.
Do survive system shut downs or server crashes.


What is the difference between stateful and stateless session beans

Stateless Session Beans
Stateful Session Bean
Do not have an internal state. Can be reused by different
clients.
Do have an internal state. Reused by the same client.
Need not be activated or passivated since the beans are
pooled and reused.
Need to handle activation and passivation to conserve system
memory since one session bean object per client.


What is the difference between Container Managed Persistence (CMP) and Bean Managed Persistence (BMP)

Container Managed Persistence (CMP)
Bean Managed Persistence (BMP)
The container is responsible for persisting state of the bean.
The bean is itself responsible for persisting its own state.
Container needs to generate database (SQL) calls.
The bean needs to code its own database (SQL) calls.
The bean persistence is independent of its database (e.g.
DB2, Oracle, Sybase etc). So it is portable from one data
source to another.
The bean persistence is hard coded and hence may not be
portable between different databases (e.g. DB2, Oracle etc).


Can an EJB client invoke a method on a bean directly

An EJB client should never access an EJB directly. Any access is done through the container. The container will intercept the client call and apply services like transaction, security etc prior to invoking the actual EJB.
This relationship between the EJB and the container is like “don’t call us, we will call you”.



What is a business delegateWhy should you use a business delegate 

Problem: When presentation tier components interact directly with the business services components like EJB, the presentation components are vulnerable to changes in the implementation of business services components.

Solution: Use a Business Delegate to reduce the coupling between the presentation tier components and the business services tier components. Business Delegate hides the underlying implementation details of the business service, such as look-up and access details of the EJB architecture.

Business delegate is responsible for:
  •  Invoking session beans in Session Facade.
  •  Acting as a service locator and cache home stubs to improve  performance.
  •  Handling exceptions from the server side. (Unchecked exceptions get wrapped into the remote exception,checked exceptions can be thrown as an application exception or wrapped in the remote exception.unchecked exceptions do not have to be caught but can be caught and should not be used in the method signature.)

  •  Re-trying services for the client (For example when using optimistic  locking business delegate will retry the method call when there is a  concurrent access.).



Also Read: Session beans

Also Read: Difference between HTTPSession and Stateful Session Bean

                                                                        Java Source World        A Java quick reference blog





No comments:

Post a Comment