Description
Antonio Anzivino created an issue — 18th March 2013, 13:18:16:
I have found a potential bug when exporting the DDL generated by a Fluent NHibernate mapping.
First, FNH has a potential issue when mapping collections to lists (i.e.
AsList()
mapping) because it hardcodes theIndex
column name to order elements in the list.When NHibernate is configured with
hbm2ddl.keywords
=auto-quote
ANDhbm2ddl.auto
!=none
|validate
then the session factory automatically runs a SQL script withIndex
columns correctly quoted.The bug happens when I want to export the DDL using
Configuration.GenerateSchemaCreationScript
.Provided the following model (which can be replaced with a generic
Entity
class with a parent-child relationship)public class ProductCategory { public virtual long Id { get; set; } public virtual string Name { get; set; } public virtual ProductCategory Parent { get; set; } public virtual IList<ProductCategory> Children { get; set; } }and provided the following FNH mapping:
internal class ProductCategoryMapping : ClassMap<ProductCategory> { public ProductCategoryMapping() { Id(x => x.Id).GeneratedBy.Increment(); Map(x => x.Name).Not.Nullable(); References(x => x.Parent) .Cascade.None(); HasMany(x => x.Children) .LazyLoad() .Cascade.None() .Inverse() .AsList(); } }Using the
GenerateSchemaCreationScript
withhbm2ddl.keywords
=auto-quote
andhbm2ddl.auto
=none
produces the following incorrect statement with MySQL 5 dialectcreate table `ProductCategory` ( Id BIGINT not null, Name VARCHAR(255) not null, Parent_id BIGINT, Index INTEGER, primary key (Id))Unquoted
index
is wrong in MySQL syntax.The problem only occurs when I use
GenerateSchemaCreationScript
and not if I useGenerateSchemaUpdateScript
with an active connection.The
Index
column name is hardcoded in FNH and cannot be changed.I think the above sample code should suffice. Small test case on the way