Hi,
I'm new to Hibernate and I got trouble with mapping using Hibernate & Spring. The exception thrown was org.hibernate.DuplicateMappingException.
I'm using inheritance mapping using joined-subclass on separate mapping file. It seems like I have to define the superclass mapping before subclass to make it work. If i put the subclass mapping first, it always throws the DuplicateMappingException. Please see the example of my mapping below.
Is there a way to make this work specially I want to specify the mapping locations to classpath*:**/*.hbm.xml in the sessionFactoryBean
Hibernate version: 3
Code:
File: Parent.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="mypackage">
<class name="Parent" table="PARENT_TABLE">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="message"/>
<property name="random"/>
<property name="type"/>
</class>
<class name="Parent2" table="PARENT2_TABLE">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="message"/>
<property name="type"/>
</class>
</hibernate-mapping>
File: Object2.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="mypackage">
<joined-subclass name="Object2" table="OBJECT2_TABLE"
extends="Parent">
<key column="id"/>
<property name="data"/>
</joined-subclass>
<joined-subclass name="Object4" table="OBJECT4_TABLE"
extends="Parent2">
<key column="id"/>
<property name="data2"/>
</joined-subclass>
</hibernate-mapping>
File: Object3.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="mypackage">
<joined-subclass name="Object3" table="OBJECT3_TABLE"
extends="Parent">
<key column="id"/>
<property name="misc_item"/>
</joined-subclass>
<joined-subclass name="Object5" table="OBJECT5_TABLE"
extends="Parent2">
<key column="id"/>
<property name="misc_item5"/>
</joined-subclass>
</hibernate-mapping>