Are Entity Beans Worth It?

   

You might find this section title to be a strange one given that this is the entity bean chapter of an EJB book. Many developers are successfully using entity beans to build complex enterprise applications while others are debating whether the benefits entity beans offer outweigh their overhead. As with most technology issues, the answer to this question depends on what you're trying to do. EJB is a heavyweight architecture that's designed to support distributed transactions and concurrent access to shared data by multiple users. There are obviously many applications that don't need the horsepower offered by EJB, and its use for them isn't appropriate. Even when EJB is appropriate for an application, some developers question whether entity beans are a good choice.

Entity beans are singled out in discussions about EJB performance and overhead in part because other alternatives exist for managing persistent data. Most of the description of entity beans focuses on persistence because that's their unique role within EJB. If all you're doing with an entity bean is simple persistence of a set of attributes, it's probably true that the overhead involved isn't justified. The first point to remember here is that entity beans are intended to do more than read and write database entries. It's true that an entity bean does this, but it should also provide the business logic associated with these attributes so that coarse-grained objects can be built up and reused across an enterprise. These reusable components can then be composed as needed to do the transactional work of a system.

Session beans are sometimes proposed as an alternative to working with the database in an EJB system. As you'll see in later chapters, this can be appropriate in certain situations. Session beans provide the same transactional support as entity beans do without some of the additional overhead. They don't, however, offer the same support for relationships between persistent objects, so you would likely use them in a limited fashion when working with the database. Perhaps more significant is that session beans don't offer the support for concurrency provided by entity beans. Access to an entity bean instance by multiple clients is managed so that use of the entity is automatically serialized. If you use a session bean to write to the database, you have to manage the possibility of simultaneous attempts to read and write the same data yourself. Session beans can be highly beneficial for read-only access to data, though. This is true even in the case of data that's mapped to an entity bean for creation and editing.

The new CMP features offered by the EJB 2.0 Specification have helped to calm some of the criticism of entity beans. As you'll see in Chapter 7 and Chapter 8, CMP now requires vendor support for managing relationships between entity beans. A common syntax also has been defined to support the implementation of finder methods . Although there are still plenty of features that would be nice to have, the latest CMP specification is definitely a step in the right direction. The increased standards should result in more sophisticated tools for implementing CMP beans and simplify the task of developing entity beans for use in multiple vendor's containers.

Java Data Objects

While EJB continues to mature in its own right, other parallel efforts are taking place that have the potential to offer some interesting solutions for enterprise development. Of particular interest when discussing entity beans is the Java Data Objects (JDO) Specification. A goal of JDO is to provide a transparent mechanism that allows application developers to build persistent classes without writing any of the persistence code themselves . This responsibility is transferred to a pluggable JDO implementation that can provide the required interaction between a persistent class and an underlying data store.

It's beyond the scope of this book to go into the details of JDO, but it's a technology you should be watching. At the time of this writing, the JDO Specification 1.0 is in proposed final draft form under the Java Community Process. The specification spells out explicit requirements for the integration of JDO with EJB. In particular, this technology is targeted toward the management of dependent objects by session beans and the persistence of BMP entity beans and their dependent objects. The potential of JDO to be a standard mechanism for managing lightweight persistent objects has caught the attention of many EJB developers looking for alternatives to entity beans.



Special Edition Using Enterprise JavaBeans 2.0
Special Edition Using Enterprise JavaBeans 2.0
ISBN: 0789725673
EAN: 2147483647
Year: 2000
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net