Java News from Wednesday, June 24, 2009

JBoss has released  Hibernate Core 3.3.2, an open source (LGPL) object relational mapping system for Java.

Hibernate Core for Java generates SQL for you, relieves you from manual JDBC result set handling and object conversion, and keeps your application portable to all SQL databases.

Hibernate provides transparent persistence, the only requirement for a persistent class is a no-argument constructor. You don't even need classes, you can also persist a model using Maps of Maps, or just about anything else. You don't even need tables, Hibernate can map entities and particular properties to SQL expressions.

Hibernate offers sophisticated query options, you can write plain SQL, object-oriented HQL (Hibernate Query Language), or create programatic Criteria and Example queries. Hibernate can optimize object loading all the time, with various fetching and caching options.

Hibernate adapts to your development process, no matter if you start with a design from scratch or work with an existing database, and it will support any application architecture. Combined with Hibernate EntityManager and Hibernate Annotations you can use Hibernate as a certified Java Persistence provider.

I've been using Hibernate regularly over multiple jobs and projects for the last couple of years, and I can't say I'm all that fond of it. The generated data mapping code just strays too far from good object oriented design principles for my taste. Too many objects and fields are mutable. Objects aren't initialized properly on construction. Too many things happen in mysterious magical ways using reflection.

Fundamentally I suspect I just don't like automatic data binding, whether to SQL databases, XML, or other data sources. Over the long term, you're better off writing your own data binding code by hand. It may take a little longer at first, and whenever you need to port your system to a new database--though how often does that ever really happen? I've seen that done once in my entire career to date--but you get a much cleaner, more comprehensible code base with fewer magical black boxes.