-->
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: duplicate import bug ?
PostPosted: Fri May 07, 2004 6:24 am 
Newbie

Joined: Fri May 07, 2004 6:05 am
Posts: 17
Hi

I need to have to classes with same name persisted by hibernate - of course they are in 2 different packages.

Hibernate version is 2.1.3 (db is postgresql, but I suspect it has nothing to do with the problem, jre is sun 1.4.2 executed in eclipse)

In the hibernate config file, I have

<mapping resource="mapping/uni/one_to_many/Personne.hbm.xml"/>
<mapping resource="mapping/bi/one_to_many/Personne.hbm.xml"/>


the first one is

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

<hibernate-mapping package="fr.addonline.hibernate_test.uni.one_to_many">

<class name="fr.addonline.hibernate_test.uni.one_to_many.Personne" table="uni1n_personne">

<id name="num" type="int" column="num" unsaved-value="any">
<generator class="sequence">
<param name="sequence">pere_num_seq</param>
</generator>
</id>

<property name="libelle" type="string" column="libelle"/>


</class>
</hibernate-mapping>

The second one is

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

<hibernate-mapping package="fr.addonline.hibernate_test.bi.one_to_many">

<class name="fr.addonline.hibernate_test.bi.one_to_many.Personne" table="bi1n_personne">

<id name="num" type="int" column="num" unsaved-value="any">
<generator class="sequence">
<param name="sequence">pere_num_seq</param>
</generator>
</id>
<property name="libelle" type="string" column="libelle"/>
</class>
</hibernate-mapping>


Both classes where simplificated for testing purpose. They are mapped to different tables, and contain only a key and a text field.

When the config file is read at startup, it hangs with a duplicate import error

INFO: Mapping class: fr.addonline.hibernate_test.uni.one_to_many.Personne -> uni1n_personne
net.sf.hibernate.MappingException: Error reading resource: mapping/uni/one_to_many/Personne.hbm.xml
7 mai 2004 11:59:58 net.sf.hibernate.cfg.Configuration add
GRAVE: Could not compile the mapping document
net.sf.hibernate.MappingException: duplicate import: Personne
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)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:249)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:285)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:333)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:990)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:946)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:889)
at fr.addonline.hibernate_test.SessionFactoryLoader.getPostgreSQLSessionFactory(SessionFactoryLoader.java:32)


When I change one of the class name Personne, say in the second case bi1n_Personne, everything works fine

the class line of the Personne.hbm.xml line becomes
<class name="fr.addonline.hibernate_test.bi.one_to_many.bi1n_Personne" table="bi1n_personne">


Do I have to design my project to avoid classes with same name even in different packages ?

I think this should be corrected in further versions on hibernate, because that's why packages are made for, and I'm pretty sure that different projects will have same name classes


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 3:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Check the log for a previous error.
duplicate import is usually due to a bug into your hbms, so simplify them till you find the pb

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 9:39 am 
Newbie

Joined: Fri May 07, 2004 6:05 am
Posts: 17
Hi,

what simplier can they be ?

there is only 2 fields, a text field and a sequence id.

Plus everything works fine when I change the classes names to be different.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 17, 2004 2:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sorry read too fast
http://www.hibernate.org/hib_docs/reference/en/html_single/#mapping-declaration-import
And check for auto-import tag

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 6:11 am 
Newbie

Joined: Fri May 07, 2004 6:05 am
Posts: 17
Thanks a lot, it solved my problem

my per-classes mapping files now start with

<hibernate-mapping package="foo" auto-import="false">



When reading this paragraph, I asked myself one more question :

<import class="ClassName" rename="ShortName"/>

what is the gain expected in declaring the alias ShortName ?
It would be really confusing because the real ClassName would be used in a Session.load and the fake ShortName in a query, both to load the same object type

wouldn't it be much simplier to rename the class to ShortName ?

I guess this option was declared to be used with objects we could not have control on.

Am I completely wrong ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 6:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The option to rename the class is of course not always an option in real projects.


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.