nhibernate验证器和envers在一起

时间:2013-03-15 17:12:35

标签: nhibernate nhibernate-validator nhibernate-envers

我试图在同一个项目中同时使用nhibernate验证器和nhibernate envers ....但我得到了null的预期:

如果我稍后对验证器进行了iniitliaze,我会收到错误:

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

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

谢谢,哈希

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

Envers初始化应始终在Validator之后发生。

另一种解决方法是,删除set ApplyToDDL是假的......那么bug就不会来......

只是为了让它发挥作用而得到了很多......