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
|