Super Simple Java ORM Framework For SQL Happy DevelopersBy Angsuman Chakraborty, Gaea News Network
Wednesday, August 9, 2006
I previously mentioned that I intended not to use any Java ORM frameworks. ORM frameworks I have seen so far have a steep learning curve and tend to shoe horn your architecture into their model. So I started fresh without any ORM frameworks like Hibernate or Spring (which I have heard is better).
I am happy coding my queries in SQL and don’t need to use any ORM specific language like Hibernate OQL. SQL is best for what it does. Why re-invent the wheel? Also I like the fine-grained control over my database as I am processing very large amount of data. My experience will be primarily relevant to sql happy java developers.
In the process (of working without any ORM framework) I realized I just needed two simple facilities over plain old JDBC.
1. I needed a way to put all the SQL queries and DDL’s in a separate file. This allows me or a DBA to later analyze the query with a fine tooth comb and optimize if necessary. It also allows me to easily change them without changing the code. Most of all cleanliness of the solution is appealing. At this point I am sure you are thinking of iBatis. I tried iBatis. Initially I liked it and thought I had my solution. However as I went down the lane I realized it too gave me features that I didn’t need. Even this was more complicated than I needed. All I needed was a HashMap saved to a file in XML format. And my database class should support query execution by name (think key-value).
2. Secondly I needed connection pooling to prevent opening and closing too many connections and also running out of connections. I found a nice solution in Proxool. Additionally it supports having multiple connection profiles in a simple text file and optionally logging queries.
3. I needed to integrate these two capabilities in a simple database class along with utility methods like cleanly closing connection and optionally logging the query data.
That’s all there is in my super simple framework, if you can even call it that. And, believe it or not, I am way more productive using it than I have been in a long time and I feel fully in control. No more burden of shoe horning my ideas to fit FooBah framework and its ideologies for me.
Update: There has been extensive discussion on this post at the ServerSide.