-->
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.  [ 2 posts ] 
Author Message
 Post subject: MappingException: duplicate import:
PostPosted: Tue Dec 07, 2004 10:37 am 
Newbie

Joined: Thu Dec 02, 2004 10:51 am
Posts: 6
Dear All:
i am new to hibernate and my code walkthrough fails on JUnit.
yesterday , i posted this same error ,and i gat some clue , however , it still seems to not respond to all my changes.

I have included my ant build file , i am not sure where i am actually using the same hibernate mapping file twice in my build file.

looking at my error stack and my build , if i can know what i have to tweak
to correct this offence.

if anyone sees this as a misleading error i will be glad to get any ideas.


thanks


Hibernate version:

Hibernate 2.1.2

Mapping documents:

build file

<?xml version="1.0"?>

<project name="hibnet" basedir="." default="all">


<!-- Project variables -->
<property name="build.src" value="src"/>
<property name="build.deprecation" value="true"/>
<property name="build.debug" value="true"/>
<property name="build.destdir" value="build"/>
<property name="javadoc.source" value="${build.src}"/>
<property name="javadoc.dest" value="api"/>
<property name="javadoc.packages" value="hinetlogic.*"/>
<property name="hibnet.lib" value="lib"/>

<!-- Write the schema to a text file -->
<property name="hibernate.args" value="--output=schema.ddl"/>
<!-- Change this to suite your desired dialect -->
<property name="hibernate.dialect" value="net.sf.hibernate.dialect.DB2Dialect"/>
<!-- This property should be the fully qualified class name of your JDBC driver -->
<property name="hibernate.conn.driver_class" value="COM.ibm.db2.jdbc.app.DB2Driver"/>
<!-- Update these properties to reflect your database -->
<property name="hibernate.conn.url" value="jdbc:db2:sample"/>
<property name="hibernate.conn.username" value="xxx"/>
<property name="hibernate.conn.password" value="xxx"/>


<!-- Path reference for the project classpath -->
<path id="project.class.path">
<pathelement path="config"/>
<pathelement path="build"/>
<fileset dir="lib">
<include name="**/*.jar"/>
<include name="**/*.zip"/>
<include name="**/*.p*"/>
</fileset>

</path>


<!-- Hibernate mapping files -->
<fileset id="hibernate.mapping.files" dir="${build.src}">
<include name="**/*.hbm.xml" />
</fileset>


<target name="all" depends="build,make-docs,gen-classes,make-props,init-db,run-tests"
description="Executes all of the targets, including the unit tests."/>
<target name="build"
description="Compiles source.">
<mkdir dir="${build.destdir}" />
<javac target="1.4"
srcdir="${build.src}"
destdir="${build.destdir}"
classpathref="project.class.path"
deprecation="${build.deprecation}"
debug="${build.debug}" />
<copy todir="${build.destdir}/hinetlogic" >
<fileset dir="${build.src}/hinetlogic" >
<include name="**/*.hbm.xml"/>
</fileset>
</copy>
</target>

<target name="make-docs" description="Generates JavaDoc.">
<mkdir dir="${javadoc.source}"/>
<javadoc sourcepath="${javadoc.source}"
destdir="${javadoc.dest}"
packagenames="${javadoc.packages}"
classpathref="project.class.path"
private="true"
author="true"/>
</target>

<target name="run-tests" depends="build" description="Runs the unit tests." >
<mkdir dir="test-results"/>
<junit fork="true" printsummary="yes" showoutput="yes">
<formatter type="plain"/>
<classpath refid="project.class.path"/>
<test name="hinetlogic.test.TestCustomerDAO" todir="test-results" outfile="result"/>
</junit>
</target>


<target name="make-props" description="Generates the hibernate.properties file.">
<propertyfile file="config/hibernate.properties" comment="hinetlogic hibernate properties">
<entry key="hibernate.dialect" value="${hibernate.dialect}"/>
<entry key="hibernate.connection.driver_class" value="${hibernate.conn.driver_class}"/>
<entry key="hibernate.connection.url" value="${hibernate.conn.url}"/>
<entry key="hibernate.connection.username" value="${hibernate.conn.username}"/>
<entry key="hibernate.connection.password" value="${hibernate.conn.password}"/>
</propertyfile>
</target>


<target name="init-db" depends="make-props" description="Creates the app database.">
<taskdef classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.class.path" name="schemaexport"/>
<schemaexport delimiter=";" drop="false" output="${basedir}/db/schema.sql"
properties="config/hibernate.properties" quiet="true" text="false">
<fileset dir="${build.destdir}">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>


<target name="gen-classes" depends="build" description="Creates the code based on the Hibernate mapping docs." >
<pathconvert refid="hibernate.mapping.files"
property="hibernate.mappings" pathsep=" " />
<java classname="net.sf.hibernate.tool.hbm2java.CodeGenerator" fork="true">
<classpath refid="project.class.path" />
<arg line="--output=${build.src}"/>
<arg line="${hibernate.mappings}"/>


</java>
</target>

</project>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

make-docs:
[javadoc] Generating Javadoc
[javadoc] Javadoc execution
[javadoc] Loading source files for package hinetlogic...
[javadoc] Loading source files for package hinetlogic.persistence...
[javadoc] Loading source files for package hinetlogic.test...
[javadoc] Loading source files for package hinetlogic.util...
[javadoc] Constructing Javadoc information...
[javadoc] Standard Doclet version 1.4.2_05
[javadoc] Building tree for all the packages and classes...
[javadoc] Building index for all the packages and classes...
[javadoc] Building index for all classes...

gen-classes:
[java] log4j:WARN No appenders could be found for logger (net.sf.hibernate.
util.DTDEntityResolver).
[java] log4j:WARN Please initialize the log4j system properly.

make-props:
[propertyfile] Updating property file: E:\hinetlogic\config\hibernate.properties


init-db:
[schemaexport] 22:36:56,144 INFO Environment:462 - Hibernate 2.1.2
[schemaexport] 22:36:56,164 INFO Environment:496 - loaded properties from resou
rce hibernate.properties: {hibernate.connection.username=xxxx, hibernate.conne
ction.password=xxxxx, hibernate.cglib.use_reflection_optimizer=true, hibernate.d
ialect=net.sf.hibernate.dialect.DB2Dialect, hibernate.connection.url=jdbc:db2:sa
mple, hibernate.connection.driver_class=COM.ibm.db2.jdbc.app.DB2Driver}
[schemaexport] 22:36:56,204 INFO Environment:519 - using CGLIB reflection optim
izer

....................................................................

[schemaexport] 22:36:56,305 INFO Configuration:166 - Mapping file: E:\hinetlogi
c\build\hinetlogic\Customer.hbm.xml

....................................................................


[schemaexport] 22:36:57,646 INFO Binder:229 - Mapping class: hinetlogic.Custome
r -> CUSTOMER
[schemaexport] 22:36:58,598 INFO Dialect:82 - Using dialect: net.sf.hibernate.d
ialect.DB2Dialect
[schemaexport] 22:36:58,608 INFO Configuration:595 - processing one-to-many ass
ociation mappings
[schemaexport] 22:36:58,608 INFO Binder:1154 - Mapping collection: hinetlogic.C
ustomer.customer -> CUSTOMER
[schemaexport] 22:36:58,608 INFO Configuration:604 - processing one-to-one asso
ciation property references
[schemaexport] 22:36:58,618 INFO Configuration:629 - processing foreign key con
straints
[schemaexport] 22:36:59,018 INFO Configuration:595 - processing one-to-many ass
ociation mappings
[schemaexport] 22:36:59,018 INFO Configuration:604 - processing one-to-one asso
ciation property references
[schemaexport] 22:36:59,028 INFO Configuration:629 - processing foreign key con
straints
[schemaexport] 22:36:59,048 INFO SchemaExport:98 - Running hbm2ddl schema expor
t
[schemaexport] 22:36:59,058 INFO SchemaExport:112 - writing generated schema to
file: E:\hinetlogic/db/schema.sql
[schemaexport] 22:36:59,069 INFO SchemaExport:117 - exporting generated schema
to database
[schemaexport] 22:36:59,109 INFO DriverManagerConnectionProvider:41 - Using Hib
ernate built-in connection pool (not for production use!)
[schemaexport] 22:36:59,119 INFO DriverManagerConnectionProvider:42 - Hibernate
connection pool size: 20
[schemaexport] 22:36:59,229 INFO DriverManagerConnectionProvider:71 - using dri
ver: COM.ibm.db2.jdbc.app.DB2Driver at URL: jdbc:db2:sample
[schemaexport] 22:36:59,229 INFO DriverManagerConnectionProvider:72 - connectio
n properties: {user=xxxx password=xxxxx}
[schemaexport] 22:37:00,080 DEBUG SchemaExport:132 - drop table CUSTOMER;
[schemaexport] 22:37:00,571 DEBUG SchemaExport:132 - drop table hibernate_unique
_key;
[schemaexport] 22:37:00,601 DEBUG SchemaExport:149 - create table CUSTOMER (
[schemaexport] name VARCHAR(255) not null,
[schemaexport] customer_Id VARCHAR(10) not null,
[schemaexport] email_address VARCHAR(50) not null,
[schemaexport] office_phone VARCHAR(20) not null,
[schemaexport] date_entered DATE not null,
[schemaexport] home_phone VARCHAR(20) not null,
[schemaexport] street VARCHAR(100) not null,
[schemaexport] state VARCHAR(20) not null,
[schemaexport] postal_code VARCHAR(10) not null,
[schemaexport] country VARCHAR(20) not null,
[schemaexport] primary key (name)
[schemaexport] );
[schemaexport] 22:37:01,071 DEBUG SchemaExport:149 - create table hibernate_uniq
ue_key (
[schemaexport] next_hi INTEGER
[schemaexport] );
[schemaexport] 22:37:01,212 DEBUG SchemaExport:149 - insert into hibernate_uniqu
e_key values ( 0 );
[schemaexport] 22:37:01,212 INFO SchemaExport:160 - schema export complete
[schemaexport] 22:37:01,232 INFO DriverManagerConnectionProvider:137 - cleaning
up connection pool: jdbc:db2:sample

run-tests:
22:37:02,123 INFO DriverManagerConnectionProvider:137 - cleaning up connection
pool: jdbc:db2:sample
[junit] Running hinetlogic.test.TestCustomerDAO
[junit] 22:37:04,677 INFO Environment:462 - Hibernate 2.1.2
[junit] 22:37:04,737 INFO Environment:496 - loaded properties from resource
hibernate.properties: {hibernate.connection.username=neuron, hibernate.connecti
on.password=admin, hibernate.cglib.use_reflection_optimizer=true, hibernate.dial
ect=net.sf.hibernate.dialect.DB2Dialect, hibernate.connection.url=jdbc:db2:sampl
e, hibernate.connection.driver_class=COM.ibm.db2.jdbc.app.DB2Driver}
[junit] 22:37:04,747 INFO Environment:519 - using CGLIB reflection optimize
r
[junit] 22:37:04,767 INFO Configuration:329 - Mapping resource: hinetlogic/
Customer.hbm.xml
[junit] 22:37:06,820 INFO Binder:229 - Mapping class: hinetlogic.Customer -
> CUSTOMER
[junit] 22:37:07,160 INFO Configuration:595 - processing one-to-many associ
ation mappings
[junit] 22:37:07,170 INFO Binder:1154 - Mapping collection: hinetlogic.Cust
omer.customer -> CUSTOMER
[junit] 22:37:07,170 INFO Configuration:604 - processing one-to-one associa
tion property references
[junit] 22:37:07,170 INFO Configuration:629 - processing foreign key constr
aints
[junit] 22:37:07,250 INFO Dialect:82 - Using dialect: net.sf.hibernate.dial
ect.DB2Dialect
[junit] 22:37:07,260 INFO SettingsFactory:62 - Use outer join fetching: tru
e
[junit] 22:37:07,290 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[junit] 22:37:07,290 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 20
[junit] 22:37:07,411 INFO DriverManagerConnectionProvider:71 - using driver
: COM.ibm.db2.jdbc.app.DB2Driver at URL: jdbc:db2:sample
[junit] 22:37:07,411 INFO DriverManagerConnectionProvider:72 - connection p
roperties: {user=neuron, password=admin}
[junit] 22:37:07,471 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of process level read-write
cache is not recommended)
....................................................................

[junit] 22:37:08,452 INFO Configuration:329 - Mapping resource: hinetlogic/
Customer.hbm.xml

............................................................................

[junit] 22:37:08,612 ERROR Configuration:252 - Could not compile the mapping
document
[junit] net.sf.hibernate.MappingException: duplicate import: Customer
[junit] at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
[junit] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
[junit] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)
[junit] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1229)
[junit] %%%% Error Creating SessionFactory %%%%
[junit] hinetlogic.persistence.DAOException: Error reading resource: hinetlo
gic/Customer.hbm.xml wraps: [net.sf.hibernate.MappingException: Error reading re
source: hinetlogic/Customer.hbm.xml]a:333)
[junit] ... 19 more
[junit] Test hinetlogic.test.TestCustomerDAO FAILED

all:

BUILD SUCCESSFUL
Total time: 30 seconds

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 6:11 pm 
Beginner
Beginner

Joined: Fri May 21, 2004 12:21 pm
Posts: 22
Location: Sacramento CA, USA
This error happens normally when you have Customer.hbm.xml more that one time in your hibernate.cfg.xml file.


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