2

我正在尝试在同一个项目中同时使用 nhibernate 验证器和 nhibernate envers ......但我得到了空期望:

如果我稍后初始化验证器,我会收到错误消息:

Mesage: Object reference not set to an instance of an object.
StackTrace:
   at NHibernate.Validator.Engine.SystemTypeExtensions.ShouldNeedValidation(Type clazz)
   at NHibernate.Validator.Engine.ValidatorEngine.GetClassValidator(Type entityType)
   at NHibernate.Validator.Engine.ValidatorEngine.AddValidator(Type entityType, IValidatableSubElementsInspector inspector)
   at NHibernate.Validator.Event.ValidatePreInsertEventListener.Initialize(Configuration cfg)
   at NHibernate.Event.EventListeners.InitializeListeners(Configuration cfg, Object[] list) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\EventListeners.cs:line 618
   at NHibernate.Event.EventListeners.InitializeListeners(Configuration cfg) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\EventListeners.cs:line 592
   at NHibernate.Cfg.Configuration.GetInitializedEventListeners() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1189
   at NHibernate.Cfg.Configuration.BuildSessionFactory() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1246
   at ....Installers.NHibernateInstaller.SessionFactoryFactory(INHibernateConfigurator nHibernateConfigurator, INHibernateEnversConfigurator nHibernateEnversConfigurator) in ...\Installers\NHibernateInstaller.cs:line 81

但如果我反过来做,我会得到错误:

Mesage: Object reference not set to an instance of an object.
StackTrace:
   at NHibernate.Validator.Cfg.ValidatorInitializer.ApplyValidatorToDDL(PersistentClass persistentClass, ValidatorEngine ve)
   at NHibernate.Validator.Cfg.ValidatorInitializer.Initialize(Configuration cfg, ValidatorEngine ve)
   at NHibernate.Validator.Cfg.ValidatorInitializer.Initialize(Configuration cfg)
   at ....NHibernateInstaller.SessionFactoryFactory(INHibernateConfigurator nHibernateConfigurator, INHibernateEnversConfigurator nHibernateEnversConfigurator) in ...\Installers\NHibernateInstaller.cs:line 83

有没有人试过这个??如何解决这个问题?

谢谢,哈里什

4

2 回答 2

1

我相信这是 NHV 的一个已知问题,https: //nhibernate.jira.com/browse/NHV-117 。

于 2013-03-16T23:09:01.700 回答
0

Envers 初始化应该总是发生在 Validator 之后。

另一个解决方法是,删除 set ApplyToDDL 为假...然后错误不会出现...

只是有一些twiks让它工作......

于 2013-03-22T17:26:42.540 回答