Tuesday, November 20, 2012

Hibernate versus Apache Commons DBUtils


When is it time to move from a simple framework to something like Hiberate, even if you only use a subset of the functionality?

In many of the applications I have to deal with, a full ORM tool is overkill.  At the same time, using straight JDBC is repetitive and error prone.  Some years ago, I started using Apache DBUtils which was an improvement over JDBC but still lacked some things.  I decided to create a wrapper around DBUtils which removed some of my remaining complaints.  Over the last few years, this wrapper has slowly morphed and increased in scope and complexity to where is better described as a framework.  It is responsible for significantly reducing errors and has eliminated certain types of errors completely.

My problem now is when an application is borderline between needing an ORM or not, which direction should be taken.  I have been going through Hibernate documentation and I realized that much of what DBUtils does can likely be done with Hibernate (thinking in terms of native SQL and POJO objects).  This is what I was reviewing when I started thinking about it.  

On further thought, it might be worthwhile to replace DBUtils with Hibernate in my current framework.  This may allow an easier transition to the full Hibernate functionality if the need arises.

Additional features provided by my framework:
* Handle some additional simple data conversions
* Provides Java enum based references to target databases
* SQL ResourceBundle & MessageFormat support with queries referenced via Java enum.
* Ability to generate nested maps from a returned POJO list.

What is missing:
* Caching of query results using a less labor intensive method

This is a good start - more updates to follow.

No comments:

Post a Comment