Java Reference
In-Depth Information
Finally, it is of particular note that Hibernate solves the problem in which the developer
needs to extract from the database a single object that is related by references to a substantial
number of objects in the database. Hibernate postpones such additional extractions until they
are actually accessed, generally avoiding substantial memory and performance costs.
Database Generation
If you are creating a new Hibernate application around an existing database, creating the
database schema is not an issue; it is presented to you on a platter. If you are starting a new
application, you will need to create the schema, the POJOs, and the mapping directly.
Yet again, Hibernate makes life easy for you. A suite of tools has been made available that
allows you to generate your database directly from the mapping file (generally using an Ant
script). This is even better than it sounds! Hibernate comes with intimate knowledge of various
different dialects of SQL, so the schema will be tailored to your particular database software—
or it can be generated for each different database to which you want to deploy your application.
The Relationship of Hibernate 3 with EJB 3.0
The current version of the EJB standard does not provide an ORM mechanism. However, this
will change. The forthcoming standard for the next (3.0) incarnation of EJB has been devel-
oped as Java Specification Request ( JSR) 220, and includes an EJB ORM standard. Why learn
Hibernate when a new standard blessed by Sun has just been released? Because the original
developers of Hibernate are closely involved in the creation of the standard, and as one of the
most successful ORM solutions, Hibernate has heavily influenced the design of EJB 3.0. Hiber-
nate will support those parts of EJB 3.0 pertaining to ORM.
EJB 3.0 supports and encourages the use of transparent persistence of entity beans that
conform to the same minimal set of requirements as the POJOs supported by Hibernate. As
a result of this, Hibernate can be used as the implementation of the EntityManager compo-
nent of an EJB container.
Hibernate's HQL (Hibernate Query Language) also has a strong correlation with the new
EJB Query Language (EJB QL)—though this is probably due as much to their common ances-
try in Structured Query Language (SQL) as it is to the Hibernate team's participation in the
standards effort.
EJB 3.0 allows the relationship between entities/POJOs and the database to be described
using annotations that Hibernate supports. The convenience of this approach suggests that it
will become the standard way to maintain these mappings as Java 5 deployments become
commonplace.
Hibernate 3 provides features above and beyond those mandated by the EJB 3.0 standard—
and Hibernate 3 does not require the presence and burden of an application server, making it
suitable for Swing applications, other client-side applications, and lightweight web apps run-
ning without a full J2EE stack (for example, those running on Tomcat).
In short, if you code to Hibernate 3 now, the effort involved in the transition to EJB 3.0
later will be minimal if at all necessary. Meanwhile, Hibernate 3 is available now and has a
persuasive pedigree.
Search WWH ::




Custom Search