Wow, just fixed the problem.
sessionFactory = configuration.buildSessionFactory(new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry());
I was missing the
.applySettings(configuration.getProperties())
Learnings
- configure() should be called AFTER setProperty
- Use
hibernate.connection.url
and NOTconnection.url
if you usehibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
- Set log4j property for hibernate logs to ALL, so that you can see more detailed issues
- To get rid of the
WARN Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
, you need to replacehttp://www.hibernate.org/dtd/
in the cfg.xml and all hbm files too. Dont forget teh hbm files, they too use the same DTD.
Lastly, referred to this, to fix this. The last advice by Bill Gorder
is superb.
private static SessionFactory configureSessionFactory()
throws HibernateException {
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.buildServiceRegistry();
return configuration.buildSessionFactory(serviceRegistry);
}