Fix db connection issue and make the code compatible with Hibernate4.