These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Classes with same name in separate assemblies/namespaces
PostPosted: Wed Sep 19, 2007 5:22 pm 
Newbie

Joined: Wed Nov 08, 2006 2:54 am
Posts: 4
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


Top
 Profile  
 
 Post subject: Re: Classes with same name in separate assemblies/namespaces
PostPosted: Tue Mar 16, 2010 7:39 pm 
Newbie

Joined: Tue Mar 16, 2010 7:19 pm
Posts: 1
Use
Code:
auto-import ="false"
in class mapping, like

Code:
<hibernate-mapping xmlns="..." namespace="Company.Product.Legacy.Domain" assembly="Company.Product.Legacy">
<class name="Order" table="Database.dbo.Order" auto-import ="false">
...
</class>
</hibernate-mapping>


Check out 5.1.2. hibernate-mapping


Top
 Profile  
 
 Post subject: Re: Classes with same name in separate assemblies/namespaces
PostPosted: Tue Jul 27, 2010 4:23 am 
Newbie

Joined: Tue Jul 27, 2010 4:21 am
Posts: 4
Could I please get a more extensive example on how to make this work, I've been struggling with:

---> NHibernate.MappingException: Could not compile the mapping document: (XmlDocument) ---> NHibernate.DuplicateMappingException: duplicate import: Documentation refers to both [MYNAME], [MYNAME], Version=1.0.0.0, Culture=neutral, PublicKeyToken=null and [MYNAME], [MYNAME], Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (try using auto-import="false").

For some time now.

And I want to do it in code, with fluent nhibernate and automapping.

Code:
    private static ISessionFactory CreateSessionFactory()
        {
            var cfg = new NotifyFluentNhibernateConfiguration();

            return Fluently.Configure()
              .Database(
               FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2005
                    .ConnectionString("Server=[MYSERVERIPADRESS]\\SOSDBSERVER;Database=NotifyTest;User ID=NHibernateTester;Password=[MYPASSWORD];Trusted_Connection=False;")
              )
             
              .Mappings(m =>
                  m.AutoMappings
                    .Add(AutoMap.AssemblyOf<SubscriptionManagerRP>(cfg));
                   )

              .BuildSessionFactory();
        }


Top
 Profile  
 
 Post subject: Re: Classes with same name in separate assemblies/namespaces
PostPosted: Tue Jul 27, 2010 9:00 am 
Newbie

Joined: Tue Jul 27, 2010 4:21 am
Posts: 4
Solved it by removing all duplicates.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.