Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
shessane opened this issue Oct 25, 2023 · 7 comments · Fixed by #3451
Closed

Comments

@shessane
Copy link

shessane commented Oct 25, 2023

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.

@fredericDelaporte fredericDelaporte changed the title [DB2400] ArgumentException Column 'SQL_TYPE_NAME' does not belong to table DataTypes, after update to 5.3 from 5.2 [DB2400] ArgumentException Column 'SQL_TYPE_NAME' does not belong to table DataTypes Nov 25, 2023
@hazzik
Copy link
Member

hazzik commented Nov 27, 2023

I'm not entirely sure how this was working in 5.2.x for you, because, in 5.2.7 both DB2Dialect and DB2400Dialect were not implementing GetDataBaseSchema method, and dialect is (still) throwing a NotSupportedException:

public virtual IDataBaseSchema GetDataBaseSchema(DbConnection connection)
{
throw new NotSupportedException();
}

@hazzik
Copy link
Member

hazzik commented Nov 27, 2023

Ok, found how, which is really bad:

try
{
if (settings.IsKeywordsImportEnabled)
{
SchemaMetadataUpdater.Update(this);
}
if (settings.IsAutoQuoteEnabled)
{
SchemaMetadataUpdater.QuoteTableAndColumns(cfg, Dialect);
}
}
catch (NotSupportedException ex)
{
// Ignore if the Dialect does not provide DataBaseSchema
log.Warn(ex, "Dialect does not provide DataBaseSchema, but keywords import or auto quoting is enabled.");
}

In short, you were using incorrect configuration in the first place. This is not a regression per se.

@bahusoid
Copy link
Member

This is not a regression per se.

So now DB2400Dialect uses wrong metadata. Still looks like regression to me (as it's caused by #2058)

Your suggestion Restore previous behavior for DB2400Dialect, eg, throwing NotSupportedException; looks like the way to go.

@hazzik
Copy link
Member

hazzik commented Nov 27, 2023

Sounds good

fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Nov 27, 2023
Fix the regression on 5.3.x, without adding proper support for DB2400 metadata

Fix nhibernate#3438
@fredericDelaporte fredericDelaporte added this to the 5.3.20 milestone Nov 28, 2023
@fredericDelaporte
Copy link
Member

fredericDelaporte commented Nov 28, 2023

This is fixed in 5.3.20 by #3451 (not yet released) by removing the metadata support for DB2/400. Feel free to recycle your current PR #3439 as a new feature, supporting the metadata for DB2/400. (Better wait for the fix to be merged back to master, which will have to wait for 5.3.20 then 5.4.x release, or merge it in your branch and work over it.)

@fredericDelaporte fredericDelaporte changed the title [DB2400] ArgumentException Column 'SQL_TYPE_NAME' does not belong to table DataTypes DB2/400: ArgumentException Column 'SQL_TYPE_NAME' does not belong to table DataTypes Nov 28, 2023
@shessane
Copy link
Author

I'll close this one and wait for master merge. Thanks

@fredericDelaporte
Copy link
Member

That is now merged on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants