The object-relational mapper for .NET

NHibernate hbm2ddl

NHibernate has a number of configuration options: Enabling statistics, Caching etc. You can check more from here

I will now talk about an unknown feature(well, at least I didn’t know until I implement SchemaValidator): hbm2ddl.auto

Hbm2ddl.auto is declarative way to use SchemaExport / SchemaUpdate / SchemaValidator (well the latter sounds odd, maybe it would be better to call it SchemaValidate, what do you think?). If you add

<property name="hbm2ddl.auto">create</property>

for example, it will run

new SchemaExport(cfg).Create(false, true);

during SessionFactory initialization, with which you probably are familiar.

There are several options for hbm2ddl.auto.

  1. update executes SchemaUpdate which will modify your existing table with new mapping, without dropping any columns.
  2. create-drop executes SchemaExport when SessionFactory initializes and drops the schema at the end of the life of the factory.
  3. validate executes SchemaValidator which I blogged about here

If you prefer not to use programatic way, configuration is just here.

Posted Sat, 22 November 2008 12:04:00 PM by tehlike
Filed under:

comments powered by Disqus
© NHibernate Community 2024