Closed bbsuuo closed 2 months ago
After downloading the source code and recompiling it myself, I managed to resolve this issue. I found significant differences in the Configuration script within the nhibernate-core library between the code on NuGet and the code on the 5.5.x branch. I'm unsure when these changes will be pushed to NuGet.
Glad you've found the issue, @bbsuuo. However, it seems that you were using old NHibernate 5.3.3 that is referenced by FluentNHibernate. It seems that instead of recompiling anything yourself you needed to install the NHibernate 5.5.1 explicitly.
I encountered an issue with the SchemaValidator and SchemaUpdate functionalities in NHibernate while using AutoMapping to construct tables. Here's a breakdown of the problem along with relevant code and error logs:
and
1.Upon the first run, the Validator throws an error: 2024-05-26 00:35:43,945 [1] ERROR NHibernate.Tool.hbm2ddl.SchemaValidator [(null)] - could not complete schema validation NHibernate.SchemaValidationException: Schema validation failed: see list of validation errors at NHibernate.Cfg.Configuration.ValidateSchema(Dialect dialect, IDatabaseMetadata databaseMetadata) at NHibernate.Tool.hbm2ddl.SchemaValidator.Validate() 2024-05-26 00:35:43,970 [1] DEBUG NHibernate.Connection.ConnectionProvider [(null)] - Closing connection 2024-05-26 00:35:43,974 [1] ERROR MySQL Service [(null)] - Error while valid database: NHibernate.SchemaValidationException: Schema validation failed: see list of validation errors at NHibernate.Cfg.Configuration.ValidateSchema(Dialect dialect, IDatabaseMetadata databaseMetadata) at NHibernate.Tool.hbm2ddl.SchemaValidator.Validate() at Server.DB.MySQL.MySQLService.SchemaCheckerCreate(Configuration config) in C:\Library\UnityLibrary\xblstudio\Server\GameServer\Server.DB\MySQL\MySQLService.cs:line 117 2024-05-26 00:35:43,977 [1] ERROR MySQL Service [(null)] - Scheme error Missing table: PayInfoEntity 2024-05-26 00:35:43,978 [1] ERROR MySQL Service [(null)] - Scheme error Missing table: PayOrderEntity 2024-05-26 00:35:43,979 [1] ERROR MySQL Service [(null)] - Scheme error Missing table: UserInfoEntity
It's fine, This error is expected since the tables have not been constructed yet. the SchemaUpdate successfully constructs all table structures without any errors.
2.Upon the second run, I receive errors from both SchemaValidator and SchemaUpdate:
2024-05-26 00:39:03,834 [1] ERROR NHibernate.Tool.hbm2ddl.SchemaValidator [(null)] - could not complete schema validation NHibernate.SchemaValidationException: Schema validation failed: see list of validation errors at NHibernate.Cfg.Configuration.ValidateSchema(Dialect dialect, IDatabaseMetadata databaseMetadata) at NHibernate.Tool.hbm2ddl.SchemaValidator.Validate() 2024-05-26 00:39:03,865 [1] DEBUG NHibernate.Connection.ConnectionProvider [(null)] - Closing connection 2024-05-26 00:39:03,868 [1] ERROR MySQL Service [(null)] - Error while valid database: NHibernate.SchemaValidationException: Schema validation failed: see list of validation errors at NHibernate.Cfg.Configuration.ValidateSchema(Dialect dialect, IDatabaseMetadata databaseMetadata) at NHibernate.Tool.hbm2ddl.SchemaValidator.Validate() at Server.DB.MySQL.MySQLService.SchemaCheckerCreate(Configuration config) in C:\Library\UnityLibrary\xblstudio\Server\GameServer\Server.DB\MySQL\MySQLService.cs:line 117 2024-05-26 00:39:03,870 [1] ERROR MySQL Service [(null)] - Scheme error Wrong column type in def.hub.userinfoentity for column UserName. Found: char, Expected VARCHAR(255)
and
2024-05-26 00:39:03,912 [1] ERROR NHibernate.Tool.hbm2ddl.SchemaUpdate [(null)] - could not complete schema update System.ArgumentException: Invalid collection name. (Parameter 'collectionName') at MySqlConnector.Core.SchemaProvider.GetSchemaAsync(IOBehavior ioBehavior, String collectionName, CancellationToken cancellationToken) in //src/MySqlConnector/Core/SchemaProvider.cs:line 59 at MySqlConnector.MySqlConnection.GetSchema(String collectionName, String[] restrictions) in //src/MySqlConnector/MySqlConnection.cs:line 535 at NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetForeignKeys(String catalog, String schema, String table) at NHibernate.Dialect.Schema.AbstractTableMetadata.InitForeignKeys(IDataBaseSchema meta) at NHibernate.Dialect.Schema.AbstractTableMetadata..ctor(DataRow rs, IDataBaseSchema meta, Boolean extras) at NHibernate.Dialect.Schema.MySQLTableMetadata..ctor(DataRow rs, IDataBaseSchema meta, Boolean extras) at NHibernate.Dialect.Schema.MySQLDataBaseSchema.GetTableMetadata(DataRow rs, Boolean extras) at NHibernate.Tool.hbm2ddl.DatabaseMetadata.GetTableMetadata(String name, String schema, String catalog, Boolean isQuoted) at NHibernate.Cfg.Configuration.GenerateSchemaUpdateScript(Dialect dialect, IDatabaseMetadata databaseMetadata) at NHibernate.Tool.hbm2ddl.SchemaUpdate.Execute(Action`1 scriptAction, Boolean doUpdate)
On the second run, both SchemaValidator and SchemaUpdate encountered errors. This is somewhat unexpected because the current database was entirely generated by the SchemaUpdate executed during the first run. Moreover, based on the error message 2024-05-26 00:39:03,870 [1] ERROR MySQL Service [(null)] - Scheme error Wrong column type in def.hub.userinfoentity for column UserName. Found: char, Expected VARCHAR(255), I meticulously examined the table structure and found that the type of UserName is VARCHAR(255) rather than char. Why would such an error occur? Furthermore, the error from SchemaUpdate is perplexing because my types haven't undergone any changes, so SchemaUpdate shouldn't encounter any errors; it shouldn't execute any operations, right?![{F477D38D-0060-470b-A1DE-C73BFD53B63C}](https://github.com/nhibernate/fluent-nhibernate/assets/35555275/80c310c1-3d1f-4e61-9d64-cbaacabc3316)