Since long time we have a very interesting request on NHibernate JIRA (NH-188).
If you are working in a multi-RDBMS application, you are annoyed, for sure, quoting a table-name or a column-name. As a very good persistent-layer this should be a NHibernate’s work.
I’m happy to announce that the problem is solved (even if, so far, is not done by default).
If you want that NH take the responsibility of properly quote table-name or column-name only where really needed now you can do it in two ways:
- Trough configuration
- Explicitly by code
Trough configuration
As you probably know NHibernate’s configuration has some property oriented to mapping-to-DLL tasks.
For schema integration you can use
<property name="hbm2ddl.auto">create-drop</property>
Allowed values for hbm2dll are:
- update : auto execute SchemaUpdate on BuildSessionFactory
- create : auto execute SchemaExport on BuildSessionFactory
- create-drop : auto execute SchemaExport on BuildSessionFactory recreating the schema
- validate : auto execute SchemaValidator on BuildSessionFactory
The new property is:
<property name="hbm2ddl.keywords">auto-quote</property>
Allowed values are:
- none : disable any operation regarding RDBMS KeyWords
- keywords : (activated by Default)imports all RDBMS KeyWords where the NH-Dialect can provide the implementation of IDataBaseSchema (so far available for MsSQL, Oracle, Firebird, MsSqlCe, MySQL, SQLite, SybaseAnywhere)
- auto-quote : imports all RDBMS KeyWords and auto-quote all table-names/column-names on BuildSessionFactory
Explicitly by code
When you have an instance of a configured configuration (just before call BuildSessionFactory) you can execute:
SchemaMetadataUpdater.QuoteTableAndColumns(configuration);
That’s all.
The advantage
Take a look to this mapping:
<class name="Order">
<id type="int">
<generator class="native"/>
</id>
<property name="Select"/>
<property name="From"/>
<property name="And"/>
<property name="Column"/>
<property name="Name"/>
</class>
Well… now it is working fine without explicitly quote.
Enjoy NHibernate’s multi-RDBMS easy support.
Posted
jun 24 2009, 12:25 a.m.
by
Fabio Maulo