Skip to content

Hibernate Duplicate Import Exception

net.sf.hibernate.MappingException: duplicate import

Section titled “net.sf.hibernate.MappingException: duplicate import”

I encountered this when I was using the ant net.sf.hibernate.tool.hbm2ddl.SchemaExportTask provided as part of the hibernate distribution. My original ant task is below.

<taskdef name="ddl"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="ddl.classpath"/>
<ddl config="src/com/magicmonster/intranet/service/hibernate.cfg.xml"
quiet="no"
text="no"
drop="no"
delimiter=";"
output="export.sql">
<fileset dir="src">
<include name="**/*.hbm.xml"/>
</fileset>
</ddl>

The duplicate exception is thrown because my configuration file, src/com/magicmonster/intranet/service/hibernate.cfg.xml, already tells hibernate to load up all the hbm.xml files. The examples in the docs assume that you’ve only got database configuration data inside the cfg.xml file. To amend this, I removed the fileset element from the task.