How to export DDL from *hbm.xml when migrating from Hibernate from 4.3 to 5.x?

Hi team,

Currently, my project is using xdoclet (2.0.1) and hibernate (4.3.10) to generate *.hbm.xml, and export SQL. I have tried to upgrade these libraries to the latest version, especially for Hibernate to version 5.6.

There are two ant targets, including java2hbm and build.db.schema. The hbm files are generated successfully and placed in the mapping directory, then the next ant target build.db.schema will export to ddl. I can generate hbm files with the new version of Hibernate, but then it is failed to export schema with the error:

Error performing export: Could not parse mapping document: D:…\model\AclTemplate.hbm.xml (FILE)

Ant task for generating hbm and SQL files:


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "">

  <class dynamic-update="true" table="acl_template" dynamic-insert="true" name="com.example.model.AclTemplate">
    <id unsaved-value="0" name="id" column="acl_template_id">
      <generator class="com.example.hibernate.StoredProcIdGenerator">
        <param name="OWNER_TYPE_DESCR">ACL_TEMPLATE</param>
    <version unsaved-value="undefined" name="version" column="version" type="long"/>
    <property name="name">
      <column name="name" length="255" not-null="true"/>
    <many-to-one cascade="none" foreign-key="FK_ACL_TEMPLATE_ORGANIZATION" class="com.example.model.Organization" name="organization">
      <column name="org_id" not-null="true"/>
    <property name="internalView">
      <column name="internal_view" not-null="true"/>
    <component name="lastUpdate" class="com.example.model.LastUpdate">
      <property name="user">
        <column name="last_upd_usr"/>
      <property name="date">
        <column name="last_upd_dt" sql-type="datetime"/>
    <set inverse="true" cascade="none" order-by="sort_order" lazy="true" table="acl_template_element" name="aclTemplateElements">
      <key column="acl_template_id"/>
      <one-to-many class="com.example.model.AclTemplateElement"/>

Phong Huynh

I have no idea what java2hbm is, but I would recommend you to migrate to annotation mappings instead. It should be pretty easy to do the migration since most hbm concepts have a same named annotation counterpart i.e. many-to-one is @ManyToOne, component is @Embedded, column is @Column etc.

Hi @beikov,

Thank you for your answer,

java2hbm is the target of ant, it will use xdoclet 2.0.1 to generate the hbm.xml files. Then target create.db.schema will use the *.hbm.xml file to export to DDL. With Hibernate 4.3, I can export successfully, but when I upgrade to Hibernate 5.6 it doesn’t work.

I don’t know the class org.hibernate.tool.hbm2ddl.SchemaExportTask is still usable with Hibenate 5.6 or not, or with the new version of Hibernate, I can’t export ddl from *hbm.xml.Or the incompatibility between xdoclet 2.0.1 and Hibernate 5.6.

Regarding your advice on using annotation, now I can’t do that because the project is big and I need to use DDL from Hibernate export.

What is the error you get when trying to export the DDL based on hbm.xml? Please print the full stack trace.

I have included it in my reply email for you. Once again, thanks for supporting me.

Include the relevant parts in here please or via private message on Discourse.

I have used org.hibernate.tool.ant.HibernateToolTask of Hibernate-tool to fix this issue. Thank you for your interest.