Enterprise Java Beans (EJB) tutorials. Focusing on EJB 3.0 (EJB3) and above.
Business method or business process is the collection of structured and related tasks which create a certain product for specified customers. Let us now code the business methods for addition/deletion and also for the retrieval of the Book Entity Beans objects. Java Code: This is an example of business methods import java.util.Collection;
Updated 01-14-2012 at 06:17 PM by EJB
Stateless session bean’s life cycle consists of 2 stages namely; ready for the invocation of the business method and non existent. Client initiates the life cycle by seeking references towards the stateless bean. Dependency injection is performed by the container and then the method annotated @PostConstruct is invoked. Now bean is ready to invoke the business methods by client. Method annotated @PreDestroy is called by the EJB container at the end of life cycle, if any. Then for garbage collection,
Home interfaces and remote interfaces present the bean however beans are insulated by the container and client application’s direct access. Whenever a bean is deleted, created or requested the whole process is managed by the container.
Component’s life cycle methods are presented by the home interfaces however bean’s business method is presented by the remote interfaces. Home & remote interfaces extends the javax.ejb.EJBHome interface and javax.ejb.EJBObject interface. Such types
Just one client can access the bean instance at any given time. There exists no persistency in case of state of the bean. They just exist for shorter time duration. State full session beans are suitable whenever: The state of bean presents the interaction b/w a specific client and the bean.The bean requires retention of certain information regarding the client, across method invocations.There occurs the mediation b/w other application components and client
A stateless session (EJB Component) is an enterprise bean which gives its users a stateless service. Interface javax.ejb.SessionBean is implemented by the stateless session bean (EJB Component) and deploys to the “stateless” declarative attribute. They are known as “stateless” as conversational states are not maintained by them that are specific to the client’s session. Stateless session beans are same as the static methods or procedural applications; no instance state is present therefore to execute
Updated 01-14-2012 at 06:14 PM by EJB
A stateful session bean is an enterprise bean (EJB component) that serves to be a client’s server side extension. It is created by one client and hence it works for just that client till the drop takes place in client connection or removal of the bean takes place explicitly. The stateful Bean (EJB Component) implements the interface javax.ejb.SessionBean and deploys to the “stateful” which is the declarative attribute. They are called stateful as conversational state is being maintained by them
Updated 01-14-2012 at 06:12 PM by EJB
Inside J2EE server, single client is presented in a session bean. It is considered as a non persistent object which makes the implementation of other business logics that run at server. Session beans are not able to survive the shut down of the system.
Two types of session beans are there: Stateless session beans (By multiple EJB clients, each session bean could be reused)Stateful session beans (every session bean is linked to just one EJB client)
The EJB container is an interface b/w enterprise bean which provides the business logic in the Java EE server or a Java EE application. EJB container is run at the Java EE server & it manages the application's enterprise beans execution. EJB Container
When to Use EJB Distributed transactions are needed.Component security needed.Persistence needed.Integration along with the legacy applications are needed.Scalability is needed.
When not use EJB When one doesn’t require application integration, transactions or other infrastructure like facilities in their application.
EJB Advantages To access EJB free security is provided.Declarative transactions are provided.EJBs are cached & pooled. Containers manage the EJB life cycles.Remote access capabilities are present & are clustered for sake of scalability.OO concepts are supported for example inheritance.Usage of attributes or annotation based programming is possible.Free usage & access of complex resources
EJB Disadvantages Complicated and large specificationIncreased
Architecture of EJB is given below. 3 kinds of interfaces are exposed by the help of EJB which are as following:
1. Home interface
2. Remote interface
3. JMS Message Listener Interface EJB Architecture
EJB is multi tier system that is distributed & remote. It supports the protocols for example, HTTP, IIOP and JRMP etc. Rapid development of the versatile, reusable and portable business components takes place across the scalable, middle ware and transactional applications. For J2EE servers, EJB is considered as a specification. System level programming and business logic are present in EJB components for example security, threading, transactions, instance pooling, persistence etc which are managed
Updated 01-15-2012 at 07:50 AM by EJB