Skip to content

NH-3427 - Configuration.GenerateSchemaCreationScript doesn't quote column names no matter hbm2ddl.keywords #1302

Open
@nhibernate-bot

Description

@nhibernate-bot

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 the Index column name to order elements in the list.

When NHibernate is configured with hbm2ddl.keywords = auto-quote AND hbm2ddl.auto != none | validate then the session factory automatically runs a SQL script with Index 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 with hbm2ddl.keywords = auto-quote and hbm2ddl.auto = none produces the following incorrect statement with MySQL 5 dialect

create 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 use GenerateSchemaUpdateScript 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions