EJB Entity Beans
By: Priya in EJB Tutorials on 2007-10-07
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
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.
<< Types of EJB
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
- Data Science
- React Native
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews
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
Steps to develop EJB Environment
EJB is a server side component: