-->
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: hibernate mapping got DuplicateMappingException
PostPosted: Wed Oct 10, 2007 9:59 pm 
Newbie

Joined: Wed Oct 10, 2007 9:30 pm
Posts: 6
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>


Top
 Profile  
 
 Post subject: have to put every class mapping into different hbm.xml files
PostPosted: Thu Oct 11, 2007 12:19 am 
Newbie

Joined: Wed Oct 10, 2007 9:30 pm
Posts: 6
I just post correction on the original code to replicate the original problem that I was having since I was combining few different mappings into one hbm.xml file.

Somehow if I separate each of the mappings into separate hbm.xml files, it all works well. So instead using 3 hbm.xml files like my first post, I use 6 hbm.xml for the mappings and I don't get DuplicateMappingException anymore.

Does anyone know what actually caused the exception in the first place?


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.