Using Hibernate as a JDBC "framework"

The ServerSide.com has an interesting article by Gavin King (Hibernate founder) on using Hibernate as a JDBC framework. A JDBC "framework" being a wrapper for all the tedious JDBC code, one which uses some simplified mechanism to streamline and consolidate the bulk of database operations and yet still allows direct SQL manipulation.

The framework is your "Data Access Layer" or "Data Access Object" layer. In applications where you are not using some built in type of persistence these frameworks become very important (when not using CMP for example).

There are many such frameworks around. There is the ultra simple and straightforward Java based SQLExecutor which is pretty much just a JDBC wrapper that consolidates code. And there are more complicated solutions that employ other features such as XML mapping like iBatis.

As it turns out Hibernate can also be used for this. Hibernate SANS the built in SQL. Normally Hibernate is used for "object relational persistence"or Object-Relational-Mapping (ORM). In the normal Hibernate world you map your objects to your database and Hibernate generates all the SQL internally, ideally you never even see or care about the SQL itself. In the Hibernate as JDBC framework world you can disable the Hibernate SQL generation and insert your own statements into XML files that control how the objects are retrieved/persisted. This in effect is a JDBC "framework".

The author of the article points out that this creating your own SQL code is often tedious, difficult to maintain and overall is probably better left to Hibernate to handle, but it can be done if thats your preference. (And he notes that if you just need the occasional manual SQL then that is different, Hibernate has handled that since the beginning, this "framework" stuff means disabling the internal SQL handling of Hibernate altogether and just letting it control the JDBC flow using your own SQL.)

For more see the linked ServerSide article. (And I plan to post more on Hibernate/Spring as I use them more and become more familiar, seems like some really cool stuff, even though I know I am way behind the curve here ;).)   Using Hibernate3 as a JDBC Framework

Comments

RE: Using Hibernate as a JDBC "framework"

Just wanted to add that in a Spring tutorial I came across Middlegen, generate all your "framework" stuff from the database (and still use Hibernate). http://boss.bekk.no/boss/middlegen/

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.