2011-05-12 94 views
0

我想就如何解决不提供细节的mappingexception提供一些帮助。呃,好的 - 有很多细节不仅仅是一个阶级或者财产。Fluent-NHibernate映射抛出“错误的标识符类型:System.Guid”

对于初学者,我刚刚升级到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来批记录进行处理;不是标识符。

我得到这一行的错误,我用流利的-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我的裤子着火了:我使用ELMAH,这对ErrorID中一个GUID。我会看看我能在常规测试引入实例为整数与一个GUID的ELMAH适当UnsavedValue集。我会测试这个,明天和发布答案。

回答

0

我刚刚从测试映射删除ELMAH,现在建立的罚款。

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

我有一个流畅的NHibernate ID约定之前设置所有 ID默认值为0,这打破了从2. *更改为3.1.0.4000。