Skip to content

DB2/400: ArgumentException Column 'SQL_TYPE_NAME' does not belong to table DataTypes #3438

Closed
@shessane

Description

@shessane

Using NHibernate to access DB2 AS400 database. When upgrading to NHibernate 5.3.13 from 5.2.7, we face a regression in the FluentConfiguration.BuildSessionFactory() :

FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

---- System.ArgumentException : Column 'SQL_TYPE_NAME' does not belong to table DataTypes.

Stack Trace: 
FluentConfiguration.BuildSessionFactory()

----- Inner Stack Trace -----
DB2MetaData.GetReservedWords()
SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
SchemaMetadataUpdater.UpdateDialectKeywords(Dialect dialect, IConnectionHelper connectionHelper)
SchemaMetadataUpdater.Update(ISessionFactoryImplementor sessionFactory)
SessionFactoryImpl.ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
Configuration.BuildSessionFactory()
FluentConfiguration.BuildSessionFactory()

The problem seems the same as #fluent-nhibernate/504

Here's the line that create the problem :

result.Add(row["SQL_TYPE_NAME"].ToString());

In a debug session I can see that there's no colomn named "SQL_TYPE_NAME". I have instead a column named "TypeName".

The workaround consists of disabling IncludeDataTypesInReservedWords :

// ...
fluentConfiguration.Database(DB2400Configuration.Standard.ShowSql().ConnectionString(connectionString)
    .Dialect<CustomDB2As400Dialect>())
//...

public class CustomDB2As400Dialect : DB2400Dialect
{
    public override IDataBaseSchema GetDataBaseSchema(DbConnection connection)
    {
        return new CustomAs400MetaData(connection);
    }

    private class CustomAs400MetaData : DB2MetaData
    {
        public CustomAs400MetaData(DbConnection connection) : base(connection)
        {
        }

        public override bool IncludeDataTypesInReservedWords => false;
    }
}

I'll try to submit a fix that returns if the column "SQL_TYPE_NAME" is not found.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions