We are currently using Spring.NET 1.1 RC1 with NHibernate 1.2 and we are in the process of building a new schema to replace a legacy database. What we're running into is a situation in which the two database schemas sometimes have name conflicts (e.g. both databases have a table called Order along with a domain class called Order). To mitigate this issue, we created separate domain and DAO assemblies so that we have something like Company.Product.Legacy.Domain.Order, Company.Product.Legacy.Dao.OrderDao, Company.Product.Domain.Order, and Company.Product.Dao.OrderDao and our mapping files use fully-qualified class and assembly names; e.g.:
<hibernate-mapping xmlns="..." namespace="Company.Product.Legacy.Domain" assembly="Company.Product.Legacy">
<class name="Order" table="Database.dbo.Order">
...
</class>
</hibernate-mapping>
The problem is that NHibernate is apparently using an unqualified reference to the Order domain class when validing the mapping files: "duplicate import: order refers to both Company.Product.Legacy.Domain.Order, Company.Product.Legacy.Domain and to Company.Product.Domain.Order, Company.Product.Domain."
Can anyone think of something we can do to allow NHibernate to recognize and use the correct classes in this situation?
Hibernate version: 1.2.0.4000
Spring version: 1.1.0.2
Full stack trace of any exception that occurs:
TestCase 'Services.Tests.Test1'
failed: System.Configuration.ConfigurationErrorsException : Error creating context 'spring.root': Error creating object with name 'SessionFactory' defined in 'file [C:\Projects\Services\Service\Service.Tests\bin\Debug\Dao.xml]' : Initialization of object failed : Could not compile the mapping document: DomainModel.Order.hbm.xml
----> Spring.Objects.Factory.ObjectCreationException : Error creating object with name 'SessionFactory' defined in 'file [C:\Projects\Services\Service.Tests\bin\Debug\Dao.xml]' : Initialization of object failed : Could not compile the mapping document: DomainModel.Order.hbm.xml
----> NHibernate.MappingException : Could not compile the mapping document: DomainModel.Order.hbm.xml
----> NHibernate.DuplicateMappingException : duplicate import: Order refers to both DomainModel.Order, DomainModel, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null and Domain.Order, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (try using auto-import="false")
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Spring.Context.Support.ContextRegistry.GetContext()
C:\Projects\Services\Service\Service.cs(85,0): at Services.Service.InjectDaos()
C:\Projects\Services\Service\Service.cs(49,0): at Services.Service.IsThis(Int32 customerId)
C:\Projects\Services\Service\Service.Tests\Test1.cs(19,0): at Services.Tests.Test1()
--ConfigurationErrorsException
at Spring.Util.ObjectUtils.InstantiateType(ConstructorInfo constructor, Object[] arguments)
at Spring.Context.Support.ContextHandler.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor)
at Spring.Context.Support.ContextHandler.ContextInstantiator.InstantiateContext()
at Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources)
at Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section)
--ObjectCreationException
at NHibernate.Cfg.Configuration.LogAndThrow(MappingException me)
at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc, String name)
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
at NHibernate.Cfg.Configuration.AddResources(Assembly assembly, IList resources, Boolean skipOrdering)
at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
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.CreateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching)
--MappingException
at NHibernate.Cfg.Mappings.AddImport(String className, String rename)
at NHibernate.Cfg.HbmBinder.BindClass(XmlNode node, PersistentClass model, Mappings mappings)
at NHibernate.Cfg.HbmBinder.BindRootClass(XmlNode node, RootClass model, Mappings mappings)
at NHibernate.Cfg.HbmBinder.BindRoot(XmlDocument doc, Mappings mappings)
at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc, String name)
Name and version of the database you are using: SQL Server 2005
The generated SQL (show_sql=true): none
|