-->
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.  [ 12 posts ] 
Author Message
 Post subject: duplicate import error
PostPosted: Sat Feb 21, 2004 10:15 pm 
Newbie

Joined: Sat Jan 31, 2004 4:32 pm
Posts: 4
Hi all,

I'm having a strange net.sf.hibernate.MappingException: duplicate import: User problem..

I've double and triple checked, and I don't seem to be declaring this mapping twice.. Can anyone see something I don't?

I can generate the error just by running generateSchema or evolveSchema tools..

Hibernate Version: 2.1.1
DB: MySQL 4.0.1

Stack trace:
Code:
net.sf.hibernate.MappingException: Error reading resource: com/gmmsolutions/echobase/datamodel/gap/Gap.hbm.xml
        at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:307)
        at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:957)
        at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:909)
        at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:860)
        at com.gmmsolutions.echobase.datamodel.tools.EvolveSchema.main(EvolveSchema.java:48)
Caused by: net.sf.hibernate.MappingException: duplicate import: User
        at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:82)
        at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
        at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:217)
        at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1204)
        at net.sf.hibernate.cfg.Configuration.add(Configuration.java:247)
        at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:281)
        at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:304)
        ... 4 more


Mapping document:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping default-cascade="save-update">

    <class name="com.gmmsolutions.echobase.datamodel.gap.security.User" table="gapusers">   
        <cache usage="read-write" />
       
        <id name="uid" type="long" column="userID">
         <generator class="native"/>
   </id>
       
        <property name="firstName" column="fname" type="string"/>
        <property name="lastName" column="lname" type="string"/>
        <!--<property name="passwordBlob" column="pwd"/>-->
        <property name="password" column="password_new" type="string"/>
        <property name="name" column="email" type="string"/>           
        <property name="enabled" column="enabled" type="boolean"/> 
       
        <set name="groups" table="gap_group_user_map" lazy="false">
            <key column="gap_user"/>
            <many-to-many column="gap_group" class="com.gmmsolutions.echobase.datamodel.gap.security.Group"/>                   
        </set>
       
        <set name="tours" inverse="true" lazy="true">
                <key column="LeaderNumber"/>
                <one-to-many class="com.gmmsolutions.echobase.datamodel.gap.Tour"/>
        </set>               
    </class>
   
    <class name="com.gmmsolutions.echobase.datamodel.gap.security.Group" table="gapgroups">
        <cache usage="read-write"/><!-- CHANGE TO READ-ONLY FOR PRODUCTION-->
       
        <id name="uid" type="long" column="groupID">
         <generator class="native"/>
   </id>
       
        <property name="name" column="name" type="string"/>
       
        <set name="users" table="gap_group_user_map" lazy="true" inverse="true">
            <key column="gap_user"/>
            <many-to-many column="gap_group" class="com.gmmsolutions.echobase.datamodel.gap.security.Group"/>                   
        </set>
       
        <set name="allowedActions" table="gap_group_allowed_actions" lazy="false">
            <key column="user_group"/>
            <many-to-many column="action" class="com.gmmsolutions.echobase.datamodel.gap.security.Action"/>                   
        </set>               
    </class>
   
    <class name="com.gmmsolutions.echobase.datamodel.gap.security.Action" table="echobase_actions">
        <cache usage="read-write"/><!-- CHANGE TO READ-ONLY FOR PRODUCTION-->

        <id name="uid" type="long" column="uniqueid">
                        <generator class="native"/>
        </id>

        <property name="name" column="entityName" type="string"/>               
    </class>
   
    <class name="com.gmmsolutions.echobase.datamodel.gap.Tour" table="i_tripdates">
        <cache usage="read-only"/>

        <id name="uid" type="long" column="dateID">
                        <generator class="native"/>
        </id>

        <property name="code" column="tcode" type="string"/>               
        <property name="codeEx" column="TripCode" type="string"/>               
        <property name="startDate" column="startDate" type="date"/>
        <property name="endDate" column="endDate" type="date"/>

        <many-to-one name="user" column="LeaderNumber" class="com.gmmsolutions.echobase.datamodel.gap.security.User"/>               
       
        <!--<set name="reports" inverse="true" lazy="true">
                <key column="tour"/>
                <one-to-many class="com.gmmsolutions.echobase.datamodel.gap.Report"/>
        </set> -->
       
        <one-to-one name="report" class="com.gmmsolutions.echobase.datamodel.gap.Report"/>       
    </class>
   
    <class name="com.gmmsolutions.echobase.datamodel.gap.Report" table="gap_reports">
        <cache usage="read-write"/>

        <id name="uid" type="long" column="tourID">
                        <generator class="foreign">
                            <param name="property">tour</param>
                        </generator>
        </id>

        <property name="comment" column="comment" type="text"/>               
        <property name="creationDate" column="creationDate" type="timestamp"/>               
        <property name="lastModifiedDate" column="lastModifiedDate" type="timestamp"/>                       
        <property name="status" column="status" type="int"/>
        <property name="singles" column="singles" type="int"/>
        <property name="doubles" column="doubles" type="int"/>
       
        <!--<many-to-one name="tour" column="tour" class="com.gmmsolutions.echobase.datamodel.gap.Tour"/>               -->
       
        <one-to-one name="tour" class="com.gmmsolutions.echobase.datamodel.gap.Tour" constrained="true"/>
       
        <set name="budgetItems" inverse="true" lazy="true" cascade="all-delete-orphan">
                <key column="report"/>
                <one-to-many class="com.gmmsolutions.echobase.datamodel.gap.ReportBudgetItem"/>
        </set>
       
        <set name="creditItems" inverse="true" lazy="true" cascade="all-delete-orphan">
                <key column="report"/>
                <one-to-many class="com.gmmsolutions.echobase.datamodel.gap.ReportCreditItem"/>
        </set>
       
        <set name="wireDeposits" inverse="true" lazy="true" cascade="all-delete-orphan">
                <key column="report"/>
                <one-to-many class="com.gmmsolutions.echobase.datamodel.gap.WireDeposit"/>
        </set>
    </class>   
   
    <class name="com.gmmsolutions.echobase.datamodel.gap.ReportNamedItem" table="gap_reportItems" >
        <cache usage="read-write"/>

        <id name="uid" type="long" column="uniqueid">
                        <generator class="native"/>
        </id>
       
        <discriminator column="itemType" type="string"/>

        <property name="name" column="name" type="string"/>               
        <property name="amount" column="amount" type="float"/>               
        <property name="comments" column="comments" type="text"/>
       
        <many-to-one name="report" column="report" class="com.gmmsolutions.echobase.datamodel.gap.Report"/>               
       
        <subclass name="com.gmmsolutions.echobase.datamodel.gap.ReportBudgetItem" discriminator-value="BUDGET">
            <key column="reportID"/>
           
            <set name="dailies" inverse="true" lazy="true" cascade="all-delete-orphan">
                <key column="reportBudgetItem"/>
                <one-to-many class="com.gmmsolutions.echobase.datamodel.gap.ReportDailyItem"/>
            </set>
        </subclass>
       
        <subclass name="com.gmmsolutions.echobase.datamodel.gap.ReportCreditItem" discriminator-value="CREDIT">
            <key column="reportID"/>       
        </subclass>               
    </class>
   
    <class name="com.gmmsolutions.echobase.datamodel.gap.ReportDailyItem" table="gap_dailyItem">
        <cache usage="read-write"/>

        <id name="uid" type="long" column="uniqueid">
                        <generator class="native"/>
        </id>
                     
        <property name="amount" column="amount" type="float"/>                       
        <property name="day" column="day" type="int"/>
        <property name="comments" column="comments" type="text"/>
       
        <many-to-one name="reportBudgetItem" column="reportBudgetItem" class="com.gmmsolutions.echobase.datamodel.gap.ReportBudgetItem"/>               
    </class>
   
    <class name="com.gmmsolutions.echobase.datamodel.gap.WireDeposit" table="gap_wireDeposits">
        <cache usage="read-write"/>

        <id name="uid" type="long" column="uniqueid">
                        <generator class="native"/>
        </id>

        <property name="accountNumber" column="accountNumber" type="int"/>               
        <property name="amount" column="amount" type="float"/>               
        <property name="bankName" column="bankName" type="string"/>                       
        <property name="date" column="date" type="timestamp"/>               
       
        <many-to-one name="report" column="report" class="com.gmmsolutions.echobase.datamodel.gap.Report"/>               
    </class>
           
</hibernate-mapping>


Thanks in advance!!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2004 10:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is most likely a DTD violation, look at the log before the error. Or upgrade to 2.1.2 which will fail more eagerly.


Top
 Profile  
 
 Post subject: Are you using XDoclet?
PostPosted: Wed Feb 25, 2004 4:48 pm 
Beginner
Beginner

Joined: Wed Dec 03, 2003 2:43 pm
Posts: 22
I had this same error, and it had to do with the XDoclet task.

Change

<hibernate/>

to

<hibernate version="2.0"/>

then it should work.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2004 3:23 pm 
Newbie

Joined: Tue Dec 30, 2003 10:46 am
Posts: 4
Hello all,

I also have the same problem, not using XDoclets, and using Hibernate 2.1.2
If the problem is the version, my lib is updated with the 2.1.2 and still receiving the message:

Caused by: net.sf.hibernate.MappingException: duplicate import: BusinessCustomer

would anyone suggest anything else ??

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 2:30 am 
Newbie

Joined: Sat Feb 28, 2004 4:42 pm
Posts: 7
Location: Oakland, California USA
luizloureiro wrote:
Hello all,

I also have the same problem, not using XDoclets, and using Hibernate 2.1.2
If the problem is the version, my lib is updated with the 2.1.2 and still receiving the message:

Caused by: net.sf.hibernate.MappingException: duplicate import: BusinessCustomer

would anyone suggest anything else ??

Thanks in advance


I am having exactly the same error as above, using hibernate.cfg.xml (vs. hibernate.properties). I've noticed that when I don't specifiy the path name to the hbm.xml file, in hibernate.cfg.xml, the mapping file is not found. If I do specify the path name to the hgm.xml file, and it is located in the same directory as the bean being mapped (as it should be), then I get the "duplicate import" error.

The examples I've seen in the docs and articles don't specify a path name in the mapping element of hibernate.cfg.xml, and place the hbm.xml file in the same directory as the bean. Maybe this doesn't have anything to do with the "duplicate import" error. Now for two of us: any help would be greatly appreciated.


Top
 Profile  
 
 Post subject: Same duplicate error for last 2 days, on Hib 2.1.1
PostPosted: Sun Feb 29, 2004 7:26 pm 
Newbie

Joined: Sun Feb 29, 2004 6:01 pm
Posts: 1
Location: London, UK
I am using Hibernate 2.1.1 developing on Windows XP, using Eclipse 3.0.0.

Originally, like the questioner above, I also moved the CLASS.hbm.xml files to the same directory as the JAVA/CLASS files and found they were not being picked up. Adding paths to the Hibernate.cfg.xml ensured they were picked up, but i get this duplicate error for each one, as I comment them in and out of the config file.

I have searched the disk and am sure there are no genuine duplicates of the file. Can't see how the same file being picked up twice would cause a duplicate so I hope this version of Hibernate isn't being confused by the Java Class and XML files having the same name ? It would be odd if it was...

... Is there anyone out there familiar enough with the Hibernate code to fully understand the "file serach" which generates this exception ? They might point the way...

I don't believe the proposed solution above (including "2.0" in hibernate) works as this appears to be part of an Ant instruction for building Hibernate whereas the original question, plus mine and the others are about problems using Hibernate in an app.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 12:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
To solve those issues, simplify your mappings and find the offending part.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 1:47 pm 
Newbie

Joined: Tue Dec 30, 2003 10:46 am
Posts: 4
Thank you all,

Just find out the problem. Indeed there was a duplicated import. It took me some time to figure it out due to lack of experience on Hibernate. My hibernate.cfg.xml had this two lines below

<mapping resource="com/provider/gfin/common/BusinessCustomer.hbm.xml" />
<mapping resource="com/provider/gfin/common/Customer.hbm.xml" />

the problem was that Customer is a subclass os BusinessCustomer, so it was mapped inside BusinessCustomer.hbm.xml and it seems you dont need to map this resource on hibernate.cgf.xml as it considers a duplicated import.

Just removed the subclass mapping resource, and it is working fine.

Hope it helps someone,

Luiz Loureiro


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 4:13 pm 
Newbie

Joined: Sat Feb 28, 2004 4:42 pm
Posts: 7
Location: Oakland, California USA
In my case at least, there is only one "standalone" class (no composition or inheritance), so improper configuration for inheritance isn't an issue. I'm still trying to find out what the problem is. I have also confirmed that there is only one .hbm.xml mapping file in my web application, so I'm still not sure why I'm getting the duplicate import error. Any other ideas/things to consider would be greatly appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 8:26 pm 
Newbie

Joined: Sat Feb 28, 2004 4:42 pm
Posts: 7
Location: Oakland, California USA
Hibernate: 2.1
mySQL: 4.0.14

There have been a couple of posts on this "duplicate imports" problem pertaining to inheritance. I'm having this same problem with a single, standalone class. Below is a stack trace, my hibernate.cfg.xml and bean mapping file, MemberRegBean.hbm.xml. Please note that there is one hbm.xml file. If I use:

<mapping resource="MemberRegBean.hbm.xml"/>

I get a "mapping resource not found" error. When specified w/path name (as shown below), I get a "duplicate import error." There is exactly one MemberRegBean.hbm.xml located on WEB-INF/classes.

I'm stuck and out of ideas right now. Any ideas would be greatly appreciated! THANKS!

########## hibernate.cfg.xml: ######################
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/aft2121</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">false</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<!--Mapping files -->
<mapping resource="/com/aft2121/memberServicesBeans/MemberRegBean.hbm.xml"/>
</session-factory>
</hibernate-configuration>

############ MemberRegBean.hbm.xml: #################

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping.dtd">

<hibernate-mapping>
<class name="com.aft2121.memberServicesBeans.MemberRegBean" table="registration">

<id name="id" column="id" type="string">
<generator class="uuid.hex"/>
</id>
<property name="firstName" column="firstName" type="string"/>
<property name="lastName" column="lastName" type="string"/>
<property name="last4SSN" column="last4SSN" type="string"/>
<property name="areaCode" column="areaCode" type="string"/>
<property name="phoneNumber" column="phoneNumber" type="string"/>
<property name="email" column="email" type="string"/>
<property name="userID" column="userID" type="string"/>
<property name="passwd" column="passwd" type="string"/>
</class>
</hibernate-mapping>


########### Java Code: ####################
#### MemberRegBean mrb is passed as a parameter.
//Configuration cfg = new Configuration();
Configuration cfg=new Configuration().configure("/hibernate.cfg.xml");
System.out.println("TWO");
cfg.addClass(MemberRegBean.class);
System.out.println("THREE");
SessionFactory sf = cfg.buildSessionFactory();
System.out.println("FOUR");
// 3. Open Session
Session sess = sf.openSession();
// 4. Save Product and close Session
Transaction t = sess.beginTransaction();
sess.save(mrb);
t.commit();
sess.close();


############### Stack trace: ############################


net.sf.hibernate.MappingException: Error reading resource: com/aft2121/memberServicesBeans/MemberRegBean.hbm.xml
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:325)
at com.aft2121.memberServicesPersistence.MemberDB.regUser(Unknown Source)
at com.aft2121.memberServicesActions.MemberRegAction.execute(Unknown Source)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536)

########### root cause here: ###############
Caused by: net.sf.hibernate.MappingException: duplicate import: MemberRegBean
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:82)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:217)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1204)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:247)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:281)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:322)
... 37 more


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 8:56 pm 
Newbie

Joined: Sat Feb 28, 2004 4:42 pm
Posts: 7
Location: Oakland, California USA
Hmm...

I think the line of code:

cfg.addClass(MemberRegBean.class);

is causing the duplicate import exception. When you use hibernate.cfg.xml and include a mapping element, does this remove the necessity of adding the class in (Java) code above?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 9:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Also, upgrade tro 2.1.3.

2.1 final incorrectly wraps some other different exceptions in "duplicate import".


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