Wednesday, September 21, 2005

A day with Hibernate

I always felt I had a sound understanding of hibernate and offered "expert" advise to my friends over chat/phone. I chanced to get Hibernate in Action and wanted to try out the traditional "Hello World!" example. Immediately fired up Eclipse and started coding, what a pleasure it is to code! I soon realized that my belief is a fallacy as there were exceptions on the console. The exception was org.hibernate.HibernateException: database product name cannot be null. Wrestled with the exception for a couple of hours but in vain. Upon retrospection, I noticed that there was an unwanted line of code

configure.setProperties(System.getProperties());

This line was overriding the properties already loaded by configure() method. If hibernate.cfg.xml is used to configure hibernate, c3p0 pool then the following lines of code would suffice:

Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();


My hibernate skills are withering and need updation, more pratice is required to keep up the pace.

No comments: