-->
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.  [ 3 posts ] 
Author Message
 Post subject: org.hibernate.MappingException: duplicate import
PostPosted: Mon Apr 11, 2005 2:43 pm 
Newbie

Joined: Mon Apr 11, 2005 2:08 pm
Posts: 8
Version 3.0


Mapping documents:
company.hbm.xml:
Code:
<hibernate-mapping package="at.rehdie.test.company">

    <import class="at.rehdie.test.product.Product"/>

    <class name="Company" table="company">
        <composite-id name="id" class="CompanyId">
            <key-property name="id" column="id" length="150"/>
        </composite-id>
       
        <property name="name" type="string" length="100"/>
       
        <bag name="products" inverse="true">
            <key column="company"/>
            <one-to-many class="Product"/>
        </bag>   
    </class>
</hibernate-mapping>

product.hbm.xml:
Code:
<hibernate-mapping package="at.rehdie.test.product">

    <class name="Product" table="product">
        <composite-id name="id" class="ProductId">
            <key-property name="id" column="id" length="150"/>
        </composite-id>
       
        <property name="name" type="string" length="100"/>
               
        <many-to-one name="company" class="Company"
              not-null="false" lazy="true" />
    </class>
   
</hibernate-mapping>

hibernate.cfg.xml:
Code:
<hibernate-configuration>

    <session-factory>

        <property name="hibernate.connection.driver_class">
            com.mysql.jdbc.Driver
        </property>

        .... some more properties
       
        <mapping resource="at/rehdie/test/company/company.hbm.xml"/>
        <mapping resource="at/rehdie/test/product/product.hbm.xml"/>
    </session-factory>

</hibernate-configuration>



Full stack trace of any exception that occurs:
org.hibernate.MappingException: Error reading resource: at/rehdie/test/product/product.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:448)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1312)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1284)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1266)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1233)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1147)
at at.rehdie.test.HibernateUtil.<clinit>(HibernateUtil.java:25)
at at.rehdie.test.Tests.newSession(Tests.java:296)
at at.rehdie.test.Tests.testCompanyProduct2(Tests.java:233)
at at.rehdie.test.Tests.main(Tests.java:309)
Caused by: org.hibernate.MappingException: duplicate import: Product
at org.hibernate.cfg.Mappings.addImport(Mappings.java:101)
at org.hibernate.cfg.HbmBinder.bindPersistentClassCommonValues(HbmBinder.java:542)
at org.hibernate.cfg.HbmBinder.bindClass(HbmBinder.java:487)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:233)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:151)
at org.hibernate.cfg.Configuration.add(Configuration.java:359)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:396)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:445)
... 10 more


I used the import-element to simplify the use of Product in the Mapping of Company. Is anything wrong with my mapping (I did not find anything in the FAQ). There are several posts for the same issue and all responses say "check, if you have your mapping twice in your config-file". Since this is not the case I'm quite confused.

There is no duplicate <mapping..> entry in the configuration.

I would suggest the following change in the class org.hibernate.cfg.Mappings (this should fix that problem):

Code:
   public void addImport(String className, String rename) throws ....
   {
      if ( imports.put(rename, className)!=null )
          throw new MappingException("duplicate import: " + rename);
   }


could be changed to

Code:
    public void addImport(String className, String rename) throws ..
    {
         String oldClassName = imports.put(rename, className);

         if (oldClassName!=null && !oldClassName.equals(className))
              throw new MappingException("duplicate import: " + rename);
    }



Should I create a Jira Issue?


Top
 Profile  
 
 Post subject: same problem ...
PostPosted: Tue Apr 12, 2005 10:22 am 
Newbie

Joined: Thu Apr 07, 2005 1:55 am
Posts: 8
I have the same Problem !! Who can help me / us ??


Top
 Profile  
 
 Post subject: I found it
PostPosted: Thu Apr 14, 2005 9:16 am 
Newbie

Joined: Thu Apr 07, 2005 1:55 am
Posts: 8
Hy ... I found the reason for this error message ... if you have a mistake in writing etc. the database tabe or the class HIBERNATE will send this "very confusing" error message ... check all the words ... and y will see ... that somewhere is a mistake ... good luck !!

assor


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.