In: Computer Science
Explain how an EJB container treats an EJB and a POJO differently and why EJB containers can support one of the Java EE goals: ease of use.
EJB full form is Enterprise Java Beans, EJB container may holds Java programming language server components or business logic and provides local and remote access to enterprise beans. EJBs today are usually "bigger, stronger, faster (or at least more scalable) and simpler" than POJOs. They are most valuable for servicing large numbers of users over the web or corporate network and somewhat less valuable for small apps within a department.EJBs can be packaged in their own jars, deployed, and invoked from lots of places. They are common components. True, POJOs can be (carefully!) designed as libraries and packaged as jars. But EJBs support both local and remote network access - including via local java interface, transparent RMI, JMS async message and SOAP/REST web service, saving from cut-and-paste jar dependencies with multiple deployments.
An EJB container will provide the runtime environment for EJB applications within the application server.It is responsible for all the operations of the EJB applications.The container acts as an intermediary action between the business logic of the bean and the rest of the world of the enterprise application.The role of EJB container is to perform transactional actions such as - i)Starting a transaction,ii) Rollback a transaction or commit a transaction,iii) Managing various connection pools for the database resources,iv)Bean’s instance variables with corresponding data items which are stored in a database will be synchronized.
In other way POJO(Plain Old Java Object) It is an ordinary Java object, not bound by any special restriction other than those forced by the Java Language Specification and not requiring any classpath. POJOs have gained the most acceptance because they are easy to write and understand. They were introduced in EJB 3.0 by Sun microsystems.POJO is an object which encapsulates Business Logic. Beans are special type of Pojos ,There are some restrictions on POJO to be a bean container- i) All JavaBeans are POJOs but not all POJOs are JavaBeans. ii)Fields should be private. This is to provide the complete control on fields.iii) Fields should have getters or setters or both.iv) A no-arg constructor should be there in a bean.v)Fields are accessed only by constructor or getter setters.
EJB container treats EJB and POJO differently because they have some difference-
EJB | POJO |
It is a special POJO which have some restrictions. | It doesn’t have special restrictions other than those forced by Java language. |
It provides complete control on members. | It doesn’t provide much control on members. |
Fields are accessed only by getters and setters. | Fields can be accessed by their names. |
Fields have only private visiblity. | Fields can have any visiblity. |
It is used when you don’t want to give restriction on your members and give user complete access of your entity | It is used when you want to provide user your entity but only some part of your entity. |
EJB containers suport java EE goals ,The Java Platform, Enterprise Edition (Java EE) provides a standards-based platform for developing web and enterprise applications. These applications are typically designed as multitier applications, with a frontend tier consisting of web frameworks, a middle tier providing security and transactions, and a backend tier providing connectivity to a database or a legacy system.Java EE platform defines APIs for different components in each tier, and also provides some additional services such as naming, injection, and resource management that span across the platform. Each component is defined in a separate specification that also describes the API, javadocs, and expected behavior.Three Main goals of the platforms are, One of the Goal is
Ease of use -
The Java EE 6 platform takes ease of use to new heights by
extensively using convention over configuration and heavy use of
annotations on a Plain Old Java Object (POJO). Adding
@Stateless @Stateful
, or
@Singleton
to a POJO makes it an Enterprise JavaBean.
Further, this could be easily packaged in a WAR file instead of a
special packaging of JAR or EAR. Servlets are POJOs as well,
annotated with @Webservlet
. Deployment descriptors
like Web.XML and Config.XML are optional in most cases; the
information typically specified in deployment descriptors is now
captured in annotations. There are default rules of navigation from
one page of JSF to another. Publishing a POJO as a RESTful web
service is equivalent to adding an @Path
annotation on
a POJO.Making deployment descriptors optional, using convention
over configuration, and relying heavily on annotations makes the
Java EE 6 platform easy to use and, above all, less verbose.