Oct 5 2009

NHibernate 2.1 tries to connect to DB on SessionFactory creation

Category: zvolkov @ 11:17

After upgrade to NHibernate 2.1, some of my integration tests started failing. I traced the error down to NHibernate SessionFactory creation. These were the tests that created SessionFactory (with invalid connection string) but never ran any queries. I figured it was the new version of NH connecting to the database on its own! Here's why:

It turns out NH 2.1 connects to DB to get list of reserved keywords. This happens in BuildSessionFactory method and is ON by default. The reason it gets the keywords is to automatically quote one if you happen to use it as a table or column name.

This behavior can be disabled by setting NHibernate configuration property hbm2ddl.keywords to the value of none.

Tags:

Comments

Comments are closed