Wednesday, November 10, 2010

Hibernate revisited

JDBC is old school and Object Relation Mapping is mainstream (and has been around for years). ORM tries to abstract tried-and-true SQL and provides objects. Theoretically you can just change from Oracle to SQLserver just by tweaking the config file and no more dealing with different SQL syntax. ORM usually means Hibernate. Anything other than Hibernate such as Toplink gets you nowhere. Java programmers today need to list Spring/Hibernate on their resume unless you run your own shop. I previously read about it and now I have some time to look into more detail... to get something simple running.

So people is not happy with the simple JDBC approach because there are some boilerplate code to open and close connections and don't like hardcoding query strings. They don't want to transfer columns into their own value objects and demands more object wrappers.

So how do your objects know about columns of your table? You provide the mapping! (1. in xml or 2. annotation)
You have to include many jars in your classpath to make it compile happily.

It comes with 2 flavors of querying: the Criteria, and HQL. To prevent a few lines of boilerplate code, you'll need to learn a new query language.

If logging is on, you will see what query, insert, update statements that it is doing. For insert, update statments it gives you lots of question marks! That's PreparedStatements in action. But there is no obvious way to see exactly what it is inserting or updating.

You know internally that it is a wrapper to JDBC and your goal is to make Hibernate crank out statements that you would use

directly in JDBC.

I fail to share the enthusiasm.... long learning curve to get something straight forward. There should be tools that generate all that mapping, POJOs for me, perhaps it would becomes useful. No one should be hacking XML or error-prone annotation by hand.

No comments: