EJB 3.0
At the present time, only the EJB 3.0 (Summer 2004 Early Draft Specification, http://jcp.org/aboutJava/communityprocess/edr/jsr220/index.html) has been made available. It is intended to obtain feedback from the community, but some probable aspects of the final release (including the clear influence of Hibernate 2.x for relational persistence) are already apparent.
Let's start by highlighting some of the similarities between EJB 3.0 and Hibernate 2.x. First and foremost, EJB 3.0 now bases container-managed persistence on plain old Java objects (POJO) with annotations, much like Hibernate's POJO + mapping file approach. From there, Hibernate's SessionManager and Session have been combined into a single EJB EntityManager class. EJB 3.0 now includes a Query class which allows for page control, similar to that of Hibernate. You are expected to mark one end of an association as inverse. And so on.
Some of the differences between Hibernate and EJB 3.0 are a natural outgrowth of the reliance of EJB 3.0 on Java 2 Standard Edition 5.0 (J2SE 5.0). For example, there is no notion of a Hibernate Configuration class, because EJB 3.0 relies on J2SE 5.0 annotations in lieu of external XML files. Extensions to EJBQL make it look more like HQL, including support for named parameters, fetch, bulk update, and bulk delete. Collection semantics go beyond the support provided in Hibernate, leveraging J2SE 5.0 generics (see JSR 14, http://jcp.org/en/jsr/detail?id=14, for more information on generics).
Some features of EJB 3.0 go significantly beyond what is offered by Hibernate 2.x. These include:
A defined distributed object environment. Session, Message, and Entity object distinctions. Additional object semantics and life cycles beyond object/relational persistence. Security permissions (including method-level security). Integrated resource-dependency references. Integrated support for exposing objects as Web services (JSR 181). A fully defined formal BNF description of the query language (important for robust parser implementations).
From the author's perspective, one of the most interesting advantages of EJB 3.0 as compared to Hibernate 2.1 HQL is the presence of a formal BNF for EJBQL. Backus Naur Form (BNF), as described at http://cui.unige.ch/db-research/Enseignement/analyseinfo/AboutBNF.html, is a formal description of a programming language. By providing a BNF, users can expect to see multiple parsers for a single language, allowing for richer and more innovative tools and solutions. For example, providing a BNF makes it much easier to produce a correct grammar for JavaCC, https://javacc.dev.java.net/. This in turn makes it much easier to produce alternative implementations for EJB 3.0 and to obtain rich support from toolsfor example, automatic type-ahead in a text editor.
For a Hibernate developer, the most shocking change when moving to EJB 3.0 is likely to be the reliance on annotations to provide persistence metadata. Simply put, EJB 3.0 development with annotations (per JSR 175, http://jcp.org/en/jsr/detail?id=175) is most similar to Hibernate development with XDoclet (as described in Chapter 3). This eliminates the need for separate XML configuration files because the information is encoded directly in the class files. The formal annotation specification (combined with solid tool support) should alleviate some problems with the current, error-prone nature of XDoclet development, but concerns about embedding database configuration information in Java source remain. The tremendous simplification of the development process may prove able to manage these concerns.
 |