| By Vijay Mandava | Article Rating: |
|
| August 23, 2002 12:00 AM EDT | Reads: |
12,746 |
Working as a BEA consultant, I've helped customers successfully design and deploy applications on various versions of the WebLogic Server (WLS). BEA has been supporting container-managed persistence (CMP) entity beans since EJB 1.0, and a few of our customers have used them. Unfortunately, some used them without understanding the ramifications; others heard about performance constraints and completely excluded entity beans from their architecture/design choices.
It was difficult to come up with reasons to use CMP entity beans when chief architects asked, "When should I consider using CMP entity beans at all?" The nirvana of entity beans lies in two things: caching and object-relational mapping. Both were done poorly in the earlier implementations, but EJB 2.0 came to the rescue. WLS 7.0's add-on features to the EJB 2.0 specification bridge the gap in performance between using entity beans and using stateless session beans with DAO and JDBC - in some cases even performing faster than the latter. When using JDBC, developers are strongly advised to use container-managed transactions.
Problems with Earlier Versions
Several customers who used entity beans in the past had to
redesign and use JDBC because their systems were too slow to meet
service-level agreements. That slowness was due to some of the
following problems:
WLS 7.0 Features
WLS 7.0 implements the EJB 2.0 specification, providing for
richer object-relational mapping. EJB 2.0 also provides the container
with a lot more flexibility for doing optimized reads and writes to
the database. The following features elucidate the richness and
flexibility developers have in designing entity beans in WLS 7.0.
Other useful features include automatic primary key generation, cascade delete support, EJB QL support, ejbSelect methods, and the concurrency strategies described below.
Concurrency Strategies
A concurrency strategy defines how many instances of an
entity bean are created, who does the locking to maintain
transactional integrity, and the access pattern of the data modeled
in the entity bean. The right concurrency strategy can make a
tremendous difference in the performance of your entity beans.
Options 3 and 4 aren't recommended because the schema of the table needs to be changed to incorporate this concurrency strategy. Also, with the optimistic concurrency strategy, you can configure whether you want caching between transactions to be true or false. With caching between transactions set to false, ejbLoad will be called at the beginning of each transaction.
Comparison
With CMP, there will always be additional processing due to
the integration of the EJB container and a layer of
container-generated code-handling transactions, security, pooling,
life-cycle management, failover, caching, and relationships. CMP (by
design or by spec) has to do internal operations, (ejbLoad, ejbStore,
ejbActivate, ejbPassivate) as opposed to JDBC logic manually
programmed by developers. The benefits of the container
infrastructure are optimized, generated database access; accelerated
development; and simplified code maintenance.
On the benchmarks I've seen, unless the data is cached, [stateless session bean + DAO (doing JDBC)] has performed 30-50% faster than the entity bean implementation.
When to Use What
Entity beans shouldn't be used as a substitute for writing
JDBC. Use entity beans if your object-relational model isn't overly
complex (involving numerous joins, etc.) and flexibility and code
maintenance are more important than raw speed for your project.
Use JDBC for simplistic, atomic-blind updates; to integrate with stored procedures and triggers; and to handle large ResultSets.
WebLogic add-ons such as the read-mostly design pattern and optimistic caching with cache-between-transactions set to true are two design choices that make entity beans an attractive option. Both are BEA-proprietary, and both are specified in the WebLogic-specific deployment descriptor. No code changes are needed when migrating to another J2EE-compliant application server. Use optimistic caching concurrency strategy if it's OK for the application to read stale data for a short period of time.
Use the read-mostly design pattern for the use case in which you read most of the time and update less frequently. This design pattern also has the shortcoming that the readers can read stale data. In case some of the readers should not read stale data at all, they can be made to read from the read-write bean.
Read-only entity beans for CMP entity beans are mentioned in the features deferred to future releases of the EJB specification. Use read-only entity beans to implement a distributed cache that can be refreshed periodically.
Conclusion
Most real-world applications do far more reads than writes.
Implementing the read-mostly pattern will provide the best of both
worlds. It provides easy development and flexible deployment, along
with excellent performance characteristics for accessing data and
paying extra overhead only when data is being modified. Optimistic
concurrency with cache-between-transactions set to true can be faster
than JDBC. Writing optimized SQL is hard for regular Java
programmers, so don't ignore entity beans - evaluate and determine
whether they're a good fit.
Entity Beans Examples
Examples are provided in subdirectories of
BEA-HOME/samples/server/src/ejb20.
References
Published August 23, 2002 Reads 12,746
Copyright © 2002 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
About Vijay Mandava
Vijay Mandava joined BEA as a technical manager in the Professional Services organization in 1999. He now works as a principal systems engineer in the Systems Engineering organization. Vijay is a Sun certified Java programmer and a BEA certified Weblogic Server developer.
![]() |
N. Bharadwaj 09/18/02 03:26:00 AM EDT | |||
This was an excellent article. Thanks to you, some of the important doubts I had on entity beans are cleared. When to use entity beans, weblogic 7.0 addons for EJB 2.0 provide a good understanding. |
||||
- Ulitzer’s Amazing First 30 Days in Public Beta
- REA Is Where RIA Becomes the Norm
- Software AG Named "Gold Sponsor" of SOA World Conference & Expo 2009 East
- Ulitzer vs. Ning - a Quick Review
- Ted Weissman and Lois Paul & Partners PR Firm
- Data.gov Will Redefine Data-as-a-Service
- SOA World Expo: Managed Methods Announces JaxView 5.0
- Product Evaluation: JBoss TCO Calculator
- Evaluating Performance Management Solutions for Java and .NET Applications
- SYS-CON Webinar: The Four Dimensions of Application Performance Monitoring
- Ulitzer’s Amazing First 30 Days in Public Beta
- REA Is Where RIA Becomes the Norm
- Software AG Named "Gold Sponsor" of SOA World Conference & Expo 2009 East
- Ulitzer vs. Ning - a Quick Review
- The Value of Inter-Domain Infrastructure Technology for SOA
- Ted Weissman and Lois Paul & Partners PR Firm
- Bull To Peddle Cassatt Cloud-Making Software
- Innovate with SOA - I
- SOA, BPM, CEP: Getting IT Budget in a Tight Economy
- Innovate with SOA - II
- Java vs C++ "Shootout" Revisited
- Configuring Eclipse for Remote Debugging a WebLogic Java Application
- Migrating a JBoss EJB Application to WebLogic
- XA Transactions
- WebLogic Tutorial: "Integrating Apache Poi in WebLogic Server"
- Eclipse "Pollinate" Project to Integrate with Apache Beehive
- Failover and Recovery of Enterprise Applications - Part 1
- Cover Story: A Practical Solution to Internationalization of a J2EE Web App
- WebSphere vs WebLogic: IBM and BEA Spar Over SPEC Results
- Developing a Service Information Portal on the WebLogic Platform








































