EJB Entity Beans

By: Priya Emailed: 1641 times Printed: 2111 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

EJB is a Java API specification that provides a component architecture for the development and deployment of distributed business objects, but many Java programmers use EJB only for its database access and Java object-persistence capabilities. If your application is highly transactional, requires high availability, and is likely to have many concurrent users, you might want to consider using EJB.

EJB is a standard part of the Java EE and is therefore supported by all Java EE–compliant application servers. Application servers that support EJB do so by providing an EJB container that hosts EJB components, just as a servlet container hosts servlets and JSPs. And just as servlet containers may be clustered to provide load balancing and fault tolerance for servlets, EJB containers can be clustered to provide the same functionality for distributed business objects. An EJB container can support three types of components: entity beans, session beans, and message beans. We won’t discuss session and message beans because they aren’t persistent. We’ll focus on entity beans, which can be persisted to a data store by using one of the following two mechanisms:

  • Container-managed persistence (CMP): You provide a mapping that specifies how to
    map fields from your entity bean objects to fields in a database, and the EJB container
    manages the persistence of your entity beans in the database.
  • Bean-managed persistence (BMP): You implement the persistence of your objects by
    using JDBC, an O/R framework, JDO, or some other technology. The EJB container will
    notify your code when it’s time to store or retrieve an object to or from the database.
    The benefits provided by using EJB for persistence are many; here are some of the most
    significant:
  • Built-in O/R framework: If you use EJB CMP, you get all the benefits of using an O/R
    framework plus the added benefits of EJB. However, the O/R mapping capabilities of
    CMP don’t address some of the harder tasks in O/R mapping such as optimistic locking,
    batch updates, and so on.
  • Scalability and high availability: EJB containers can be clustered to allow your application
    to scale up to meet the needs of more and more users. If an EJB container fails, the
    objects that were running in that container will automatically and transparently failover
    to continue execution in another EJB container.
  • Declarative transaction support: EJB allows you to declare the transactional characteristics
    of your business objects. Instead of writing the code to begin and end
    transactions, you simply declare the transactional requirements of each of your
    object’s methods and let the EJB container do the rest. If you have a complex and
    highly transactional system, this is an important benefit.
  • Declarative method-level security: EJB allows you to declare the security characteristics
    of your business objects. Instead of writing code to ensure that only certain users
    working in certain roles can use your objects, you simply declare the security constraints
    of each of your object’s methods and let the EJB container handle the security.
  • Distributed object support: EJB is designed to support the development and deployment
    of distributed business objects that are callable via Java Remote Method
    rotocol (IIOP).

One disadvantage of EJB is complexity. The technology is complex, and the learning curve is steep. To learn EJB development, you need to learn the EJB philosophy, the EJB API, recommended EJB patterns, EJB development tools, and the EJB deployment descriptors. To learn EJB deployment, you need to learn how to use the administration and deployment tools provided by the various Java EE application servers that you intend to support, each of which can vary quite significantly.

Another disadvantage of EJB is development overhead. When EJBs were first introduced, you needed to create at least three (often four) files for a single EJB. Tools such as XDoclet made the process easier, but until recently there was a lot of complexity in developing even simple beans. EJB 3.0, part of the latest Java Platform, Enterprise Edition 5 specification, has made steps to make the writing process easier, but there are still many issues to understand and consider. There is also considerable runtime overhead associated with using entity beans as the container interposes a variety of services for your beans. EJB does a lot for you, but with increased complexity and significant development overhead. Make sure that you really need the benefits provided by EJB before you commit to using it in your application.


EJB Home | All EJB Tutorials | Latest EJB Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(4)


1. View Comment

really understandable
but 'm expecting with more examples


View Tutorial          By: rajkumar at 2008-03-14 03:53:21
2. View Comment

It is really very gud. And wht i suggest u is if u post this kind of things,ples do forward to my mail also.please do tht.
and All the Best for ur future.


View Tutorial          By: Ragava rao at 2008-07-19 05:33:18
3. View Comment

Article is good but really lacks somewhat clarity in ideas. But overall its really wonderfull and helpfull also.

View Tutorial          By: Ashwin Perti at 2009-09-14 04:02:39
4. View Comment

please try to elaborate the explanation with examples

View Tutorial          By: bhavitha at 2014-02-21 06:09:12

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Priya
Getting started with ASP
EJB Entity Beans
Error Handling - Stderr and Exit - sample program in C
Pointers and Arrays in C
Data Types and Sizes in C
virtual inheritance example in C++
ctime() sample program in C++
TextBox sample program in J2ME
Advantages of Java Beans
list() contents of a Directory - sample program in Java
File example program in Java
continue and break statements in C++
Use of 'throw' in Java
Passing parameters to a function by value in C++
Demonstrating global and local variables in C++

More Tutorials in EJB
EJB 3 Entities
Web services basics
Required Classes/Interfaces That Must Be Provided for an Enterprise JavaBeans Component
Difference Between Session and Entity Beans
Difference Between Stateful and Stateless Session Beans
Managing Security in EJB
EJB Entity Beans
Types of EJB

More Latest News
Most Viewed Articles (in EJB )
Difference Between Stateful and Stateless Session Beans
Types of EJB
Managing Security in EJB
Difference Between Session and Entity Beans
EJB Entity Beans
Required Classes/Interfaces That Must Be Provided for an Enterprise JavaBeans Component
Web services basics
EJB 3 Entities
Most Emailed Articles (in EJB)
Difference Between Session and Entity Beans
Types of EJB
Difference Between Stateful and Stateless Session Beans
EJB 3 Entities
EJB Entity Beans
Required Classes/Interfaces That Must Be Provided for an Enterprise JavaBeans Component
Managing Security in EJB
Web services basics