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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: MappingException: duplicate import
PostPosted: Mon Oct 17, 2005 5:16 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
Hi, I have the following HBM files. When I build NHibernate I get duplicate import whiche should not happen since they belong to diffrent namespaces

first hbm

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras.IntegracionRentabilidad.Estados"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="field">

   <class
      name="EstadoNecesidadIntegracion"
        table="E_Estado_Necesidad_Integracion"
        mutable="false">
       
        <jcs-cache usage="read-only" />
       
        <id
         name="mId"
         column="estadoNecesidadIntegracion_ID"
         type="Int32">
         <generator class="assigned" />
      </id>
      
      <discriminator
         column="tipoEstadoNecesidadIntegracion_Class"
         type="string"
         length="5" />
      
      <property
         name="mDescripcion"
         column="X_estadoControl"
      />

      <!-- ================================  -->
      <!-- Subclass Pendiente               -->
      <!-- ================================  -->
      <subclass
         name="Pendiente"
         discriminator-value="PEN" >
      </subclass>
      
      <!-- ================================  -->
      <!-- Subclass Incial               -->
      <!-- ================================  -->
      <subclass
         name="Inicial"
         discriminator-value="INI" >
      </subclass>
      
      
      <!-- ================================  -->
      <!-- Subclass Incompleto            -->
      <!-- ================================  -->
      <subclass
         name="Incompleto"
         discriminator-value="INC">
      </subclass>
      
      <!-- ================================  -->
      <!-- Subclass Integrado               -->
      <!-- ================================  -->
      <subclass
         name="Integrado"
         discriminator-value="INT">
      </subclass>
      
   </class>
</hibernate-mapping>


second hbm

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras.EstadosControles"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="field">

   <class
      name="EstadoControl"
        table="E_Estado_Control"
        mutable="false">
       
        <cache usage="read-only" />
       
        <id
         name="mId"
         column="estadoControl_ID"
         type="Int32"
         access="field">
         <generator class="assigned" />
      </id>
      
      <discriminator
         column="tipoEstadoControl_Class"
         type="string"
         length="5" />
      
      <property
         name="mDescripcion"
         column="X_estadoControl"
      />
      
      <!-- ================================  -->
      <!-- Subclass Inicial               -->
      <!-- ================================  -->
      <subclass
         name="Inicial"
         discriminator-value="INI">
      </subclass>
      <!-- ================================  -->
      <!-- Subclass Ejecutando            -->
      <!-- ================================  -->
      <subclass
         name="Ejecutando"
         discriminator-value="EJE">
      </subclass>
      <!-- ================================  -->
      <!-- Subclass ConErrores            -->
      <!-- ================================  -->
      <subclass
         name="ConErrores"
         discriminator-value="CERR">
      </subclass>
      <!-- ================================  -->
      <!-- Subclass Finalizado            -->
      <!-- ================================  -->
      <subclass
         name="Finalizado"
         discriminator-value="FIN">
      </subclass>
      <!-- ================================  -->
      <!-- Subclass PendienteJustificacion   -->
      <!-- ================================  -->
      <subclass
         name="PendienteJustificacion"
         discriminator-value="PJUS">
      </subclass>
      <!-- ================================  -->
      <!-- Subclass Inconsistente            -->
      <!-- ================================  -->
      <subclass
         name="Inconsistente"
         discriminator-value="INC">
      </subclass>
   </class>
</hibernate-mapping>


Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 10:28 am 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
No news on this bug?? I'm starting to have to get really inventive with class names if this bug is not solved.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 9:58 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Please enter a bug report in JIRA


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 7:53 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
I think I may be running into the same problem. I'm trying to subclass a class in another namespace that has the same name.

I want to subclass a class named "AT.Persistence.Entity.User" with the name "Reservations.Persistence.Entity.User."

I'm using the following mapping file. I also tried making the name in the subclass element fully qualified, but, it didn't seem to help.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
  assembly="ReservationsLibrary"
  namespace="Reservations.Persistence.Entity">
  <subclass name="User" extends="AT.Persistence.Entity.User, ATLibrary">
  </subclass>
</hibernate-mapping>

And I'm getting the following exception when I attempt to create the database using SchemaExport.

Code:
Unhandled Exception: NHibernate.MappingException: duplicate import: User
   at NHibernate.Cfg.Mappings.AddImport(String className, String rename)
   at NHibernate.Cfg.Binder.BindClass(XmlNode node, PersistentClass model, Mappings mapping)
   at NHibernate.Cfg.Binder.BindSubclass(XmlNode node, Subclass model, Mappings mappings)
   at NHibernate.Cfg.Binder.BindRoot(XmlDocument doc, Mappings model)
   at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc)
   at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream)
   at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly, Boolean skipOrdering)
   at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
   at Reservations.Program.Main(String[] args) in C:\Documents and Settings\jemiller\My Documents\Visual Studio 2005\Projects\Reservations\CreateDatabase\Program.cs:line 20

Does anyone know if it's possible to do this? Or, is it a known limitation? Was it ever fixed previously?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 5:18 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Has anyone else got this to work? Am I doing something wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 3:12 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
jemiller wrote:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
  assembly="ReservationsLibrary"
  namespace="Reservations.Persistence.Entity">
  <subclass name="User" extends="AT.Persistence.Entity.User, ATLibrary">
  </subclass>
</hibernate-mapping>



Given that auto-import defaults to true, maybe one (or both) of the mapping files should specify
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
  auto-import="false" [cut]>


Gert


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 1:03 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
It worked!!! You rule Gert. Thanks! :-) I've been wanting to get this to work for probably years now and it's finally working (I've been trying to get this to work in the Java version of Hibernate too).

This is a big help because this way I can have a common library that has base classes that implement most of what I need and then have subclasses in a different package that have extended functionality that is specific to a particular application and still have reasonable names. For example, I can have a User class in my common library and then have one in my application that has to do with reservations and add a Reservations property to that class to get a list of reservations for a user.

Thanks, much appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 1:06 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
I'd give you a credit, but, I don't think it will let me since I didn't start the thread. At any rate, thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 3:31 am 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:50 pm
Posts: 22
After making this change, in your HQL do you now need to specify the fully qualified name when referencing these objects?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 12:55 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
I set auto-import to false on the subclass and I left it set to true on the super class. I found that if I do a query with the unqualified name, it will return objects of the superclass and the subclass. If I want just the objects of the subclass, then, I have to specify that fully qualified name. I don't remember what happens if I specify the fully qualified name of the superclass (whether it returns specifically just the superclass types, or, if that includes the child classes, I'm guessing it's probably the later).


Top
 Profile  
 
 Post subject: duplicate import error
PostPosted: Tue May 16, 2006 6:45 am 
Newbie

Joined: Wed Mar 29, 2006 4:42 am
Posts: 11
Location: Ware, Herts., UK
Just wanted to add a recommendation for Gert's solution to this post.

I've just encountered the duplicate import problem and setting the auto-import attribute to false in the hibernate-mapping element in the .hbm.xml file solves the problem nicely.

Many thanks.


Top
 Profile  
 
 Post subject: Re: duplicate import error
PostPosted: Tue May 16, 2006 7:19 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
David Dilworth wrote:
I've just encountered the duplicate import problem and setting the auto-import attribute to false in the hibernate-mapping element in the .hbm.xml file solves the problem nicely.


You didn't specify if You use fully qualified names in HQL queries? Or if You have many mapping files and You set this attribute for only one of them? Or if You import needed classes manually?

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 8:56 am 
Newbie

Joined: Wed Mar 29, 2006 4:42 am
Posts: 11
Location: Ware, Herts., UK
Actually I ran into the problem when I was using the HbmSerializer, which is part of the NHibernate.Mapping.Attributes (NHMA) namespace.

I had marked-up two classes which had the same name with the relevant NHMA attributes. My two classes were in different namespaces.

Trying to create an NHibernate configuration using my serialized assembly gave me the error.

As I said, setting the auto-import attribute to false solved the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 9:44 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
David Dilworth wrote:
Actually I ran into the problem when I was using the HbmSerializer, which is part of the NHibernate.Mapping.Attributes (NHMA) namespace.

I had marked-up two classes which had the same name with the relevant NHMA attributes. My two classes were in different namespaces.

Trying to create an NHibernate configuration using my serialized assembly gave me the error.

As I said, setting the auto-import attribute to false solved the problem.


I did totally misread Your post. Please diregard my previous answer ;) My only defence is that I'm not native english speaker :-P

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 5:25 pm 
Newbie

Joined: Tue Apr 24, 2007 3:34 pm
Posts: 2
Location: Ohio, USA
David Dilworth wrote:
Actually I ran into the problem when I was using the HbmSerializer, which is part of the NHibernate.Mapping.Attributes (NHMA) namespace.


How would one specify the <import class="..."> setting using the Mapping.Attributes contrib (v.1.0.3)?

I tried sticking the ImportAttribute onto the class: it didn't work because ImportAttribute is restricted to fields and properties. So I tried attaching it to one of my properties in the class: then it just gets dropped and no <import> is output into the configuration.

Ideas?

Thanks,
Alex


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

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.