2011-05-12 47 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。