Fluent-NHibernate映射抛出“Bad identifier type:System.Guid”

时间:2011-05-12 21:38:42

标签: nhibernate fluent-nhibernate mappingexception

我想在如何解决没有提供详细信息的mappingexception方面提供一些帮助。呃,好的 - 有很多细节,不是一个阶级或财产。

首先,我刚升级到NH3.1和FNH 1.2。我有一个类用于为NHibernate(3.1.0.4000)构建一个SQLite数据库。我在尝试隔离问题的流畅的nhibernate(1.2.0.712)映射时遇到了麻烦。

错误是:

System.InvalidCastException: Unable to cast object of type 'NHibernate.Type.SerializableType' to type 'NHibernate.Type.IIdentifierType'. at NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(String unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor) NHibernate.MappingException: Bad identifier type: System.Guid at NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(String unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor) at NHibernate.Tuple.PropertyFactory.BuildIdentifierProperty(PersistentClass mappedEntity, IIdentifierGenerator generator) at NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass persistentClass, ISessionFactoryImplementor sessionFactory) at NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory) at NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping) at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg) at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) at NHibernate.Cfg.Configuration.BuildSessionFactory() at MYPROJ.DatabaseConfigurer.OpenSession(DbEnum database) in DatabaseConfigurer.cs: line 37 at MYPROJ.user_specification.<.ctor>b__5() in UserSpecs.cs: line 670

的Guid?什么Guid?我的映射中没有任何Guid作为标识符。我在一个类中有一个Guid作为属性 - 我使用guid批处理记录以供服务处理;不是标识符。

我在这一行得到了错误,我使用fluent-nhibernate(1.2.0.712)实例化了一个内存中的SQLiteConfiguration:

var sessionFactory = configuration.BuildSessionFactory();

我打开log4net基本配置来登录文件,但找不到任何错误。这是该日志的尾部:

2011-05-12 15:29:04,152 [1] ?.lambda_method(:0) - processing filters (second pass)
2011-05-12 15:29:04,199 [1] ?.lambda_method(:0) - Using dialect: NHibernate.Dialect.SQLiteDialect
2011-05-12 15:29:04,277 [1] ?.lambda_method(:0) - Using dialect defined converter
2011-05-12 15:29:04,277 [1] ?.lambda_method(:0) - Generate SQL with comments: disabled
2011-05-12 15:29:04,277 [1] ?.lambda_method(:0) - Initializing connection provider: NHibernate.Connection.DriverConnectionProvider
2011-05-12 15:29:04,277 [1] ?.lambda_method(:0) - Configuring ConnectionProvider
2011-05-12 15:29:04,277 [1] ?.lambda_method(:0) - Transaction factory: NHibernate.Transaction.AdoNetWithDistributedTransactionFactory
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Optimize cache for minimal puts: False
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Connection release mode: on_close
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Default batch fetch size: 1
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - echoing all SQL to stdout
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Statistics: disabled
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Deleted entity synthetic identifier rollback: disabled
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Query translator: NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Query language substitutions: {'true'='1', 'false'='0'}
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - cache provider: NHibernate.Cache.NoCacheProvider, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Wrap result sets: disabled
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Batcher factory: NHibernate.AdoNet.NonBatchingBatcherFactory, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Default entity-mode: Poco
2011-05-12 15:29:04,293 [1] ?.lambda_method(:0) - Named query checking : enabled
2011-05-12 15:29:04,324 [1] ?.lambda_method(:0) - building session factory
2011-05-12 15:29:04,324 [1] ?.lambda_method(:0) - Session factory constructed with filter configurations : {}
2011-05-12 15:29:04,324 [1] ?.lambda_method(:0) - instantiating session factory with properties: {'connection.provider'='NHibernate.Connection.DriverConnectionProvider', 'proxyfactory.factory_class'='NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle', 'connection.driver_class'='NHibernate.Driver.SQLite20Driver, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4', 'dialect'='NHibernate.Dialect.SQLiteDialect, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4', 'hibernate.dialect'='NHibernate.Dialect.SQLiteDialect, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4', 'query.substitutions'='true=1;false=0', 'connection.release_mode'='on_close', 'show_sql'='true', 'connection.connection_string'='Data Source=:memory:;Version=3;New=True;'}
2011-05-12 15:29:04,324 [1] ?.lambda_method(:0) - Obtaining IDbConnection from Driver
2011-05-12 15:29:04,324 [1] ?.lambda_method(:0) - Closing connection

Log4net没有提供任何见解,是否有另一种方法可以调试此异常以显示类或属性?

由于

修改 我使用IIdConvention来设置我的主键和 ahem 我的裤子着火了:我使用Elmah,它有一个用于ErrorId的GUID。我将看看我是否可以在我的约定中测试传入的实例,以便为整数设置正确的UnsavedValue而不是针对Elmah的Guid。我明天将测试并发布答案。

1 个答案:

答案 0 :(得分:0)

我刚从测试映射中移除了Elmah,现在它构建得很好。

Engine.UnsavedValueFactory.GetUnsavedIdentifierValue抛出错误,因为0不是GUID的有效默认值。

我有一个Fluent NHibernate ID约定,之前设置了所有 ID,默认值为0,而且从2. *更改为3.1.0.4000。