-->
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.  [ 6 posts ] 
Author Message
 Post subject: MappingException duplicate import:
PostPosted: Sun Jul 11, 2004 9:59 pm 
Newbie

Joined: Thu Jul 08, 2004 11:20 pm
Posts: 6
Hi,
Am using Hibernate 2.1. with MySql. When I try to run my project I am getting the MappingException:

09:44:17,828 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
09:44:17,828 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
09:44:17,843 INFO [Configuration] Mapping resource: au/com/isell/test/Product.hbm.xml
09:44:17,859 ERROR [Configuration] Could not compile the mapping document
net.sf.hibernate.MappingException: duplicate import: Product
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:126)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1243)

what does this mean please? I have one object - Product, with one mapping file:

<hibernate-mapping>
<class name="au.com.isell.test.Product" table="products">
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="name">
<column name="name" sql-type="char(255)" not-null="true"/>
</property>
<property name="price">
<column name="price" sql-type="double" not-null="true"/>
</property>
<property name="amount">
<column name="amount" sql-type="integer" not-null="true"/>
</property>
</class>
</hibernate-mapping>

my config XML is thus:

<hibernate-configuration>
<session-factory name="java:comp/env/hibernate/SessionFactory">
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">
jdbc:mysql:///hibernate_tutorial</property>
<property name="dialect">
net.sf.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.connection.username">xxx</property>
<property name="hibernate.connection.password">xxx</property>
<mapping resource="au/com/isell/test/Product.hbm.xml"/>
</session-factory>
</hibernate-configuration>


I have only one instance of this object, with only one mapping. What is being duplicated?

thanks for any help

Paul.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 11, 2004 10:02 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Show the code that initializes the SessionFactory.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: src
PostPosted: Sun Jul 11, 2004 10:12 pm 
Newbie

Joined: Thu Jul 08, 2004 11:20 pm
Posts: 6
try {

Configuration cfg = new Configuration().addClass(Product.class);
cfg.configure("/hibernate.cfg.xml");
new SchemaUpdate(cfg).execute(true,true);

SessionFactory sf = cfg.buildSessionFactory();
Session sess = sf.openSession();
Transaction t = sess.beginTransaction();

Product p = new Product();
p.setAmount(10);
p.setName("EJB Beans");
p.setPrice(10000.00);
sess.save(p);

t.commit();
sess.close();
} catch (Exception e) {
e.printStackTrace();
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 11, 2004 10:15 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Either addClass() or name it in hibernate.cfg.xml.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: addClass(..)
PostPosted: Sun Jul 11, 2004 10:20 pm 
Newbie

Joined: Thu Jul 08, 2004 11:20 pm
Posts: 6
is that not what this is doing?

Configuration cfg = new Configuration().addClass(Product.class);

how do I addClass in the cfg.xml?

Thanks

Paul.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 5:17 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Either call addClass(Product.class) or name the Product class in the hibernate.cfg.xml, but don't do both.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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