错误:Spring.Objects.Factory。ObjectCreationException:在“程序集”中定义名为“NHibernate SessionFactory”的错误创建对象

时间:2021-12-27 08:54:49

I get the following error when running any NUnit integration test

在运行任何NUnit集成测试时,都会遇到以下错误。

- Assembly setup complete -
Beginning Processing of Tests -
Test 'PXL.IntegrationTests.EventDaoTests.deleteEvent' failed: Spring.Objects.Factory.ObjectCreationException : Error creating object with name 'NHibernateSessionFactory' defined in 'assembly [PXL.Dao.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null], resource [PXL.Dao.NHibernate.Dao.Dao.xml] line 18' : Initialization of object failed : Association references unmapped class: PXL.Domain.TBEvent
  ----> NHibernate.MappingException : Association references unmapped class: PXL.Domain.TBEvent
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure)
at Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments)
at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure)
at Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects)
at Spring.Objects.Factory.ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(IListableObjectFactory factory, Type type, Boolean includePrototypes, Boolean includeFactoryObjects)
at Spring.Dao.Support.PersistenceExceptionTranslationInterceptor.DetectPersistenceExceptionTranslators(IListableObjectFactory objectFactory)
at Spring.Dao.Attributes.PersistenceExceptionTranslationPostProcessor.set_ObjectFactory(IObjectFactory value)
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper)
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure)
at Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments)
at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure)
at Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects)
at Spring.Context.Support.AbstractApplicationContext.RegisterObjectPostProcessors(IConfigurableListableObjectFactory objectFactory)
at Spring.Context.Support.AbstractApplicationContext.Refresh()
at Spring.Testing.NUnit.AbstractSpringContextTests.LoadContextLocations(String[] locations)
at Spring.Testing.NUnit.AbstractDependencyInjectionSpringContextTests.SetUp()
--MappingException
at NHibernate.Cfg.XmlHbmBinding.CollectionBinder.BindCollectionSecondPass(XmlNode node, Collection model, IDictionary`2 persistentClasses, IDictionary`2 inheritedMetas)
at NHibernate.Cfg.XmlHbmBinding.CollectionBinder.<>c__DisplayClassd.<AddCollectionSecondPass>b__c(IDictionary`2 persistentClasses)
at NHibernate.Cfg.Configuration.SecondPassCompile()
at Spring.Data.NHibernate.LocalSessionFactoryObject.AfterPropertiesSet()
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InvokeInitMethods(Object target, String name, IConfigurableObjectDefinition definition)
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper)
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure)

Assembly TearDown

0 passed, 1 failed, 0 skipped, took 4.67 seconds (NUnit 2.5.5).

The line of code that the error refers to is the NHibernate Dao Configuration 1st line.

错误引用的代码行是NHibernate Dao配置第一行。

<!-- NHibernate Configuration -->
<object id="NHibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate21" scope="application">
    <property name="DbProvider" ref="DbProvider"/>
    <property name="MappingAssemblies">
        <list>
            <value>PXL.Dao.NHibernate</value>
        </list>
    </property>
    <property name="HibernateProperties">
        <dictionary>
            <entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
            <entry key="dialect" value="NHibernate.Dialect.MsSql2008Dialect"/>
            <entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
        </dictionary>
    </property>

    <!-- provides integation with Spring's declarative transaction management features -->
    <property name="ExposeTransactionAwareSessionFactory" value="true" />
</object>

The missing file that it refers to "Association references unmapped class: PXL.Domain.TBEvent" does exist and as far as I can see there is nothing missing, the mapping file has no errors in it and there is a cs file for it to map to and all the interfaces exist and the row in the dao which refers to it also exists.

“关联引用未映射类:PXL.Domain”的缺失文件。TBEvent“确实存在,就我所见,没有什么遗漏,映射文件没有任何错误,并且有一个cs文件可以映射到,所有的接口都存在,而dao中引用的行也存在。

<object id="TBEventDao" type="PXL.Dao.NHibernate.HibernateTBEventDao, PXL.Dao.NHibernate">
    <property name="SessionFactory" ref="NHibernateSessionFactory"/>
</object>

I know this is something simple, wonder if anyone here can give me some insight.

我知道这很简单,不知道这里有没有人能给我一些启示。

1 个解决方案

#1


3  

Make sure the Build Action of your mapping xml file is set to Embedded Resource and that the extension is .hmb.xml.

确保将映射xml文件的构建操作设置为嵌入资源,扩展是.hmb.xml。

#1


3  

Make sure the Build Action of your mapping xml file is set to Embedded Resource and that the extension is .hmb.xml.

确保将映射xml文件的构建操作设置为嵌入资源,扩展是.hmb.xml。