There are some parts of a Hibernate hbm.xml file that cannot be
generated from XDoclet hibernatedoclet @tags in your source with XDoclet
1.2.b4. In my case, I needed to include:
Code:
<!-- Included by Hibernate XDoclet task into the hbm.xml -->
<any name="referredToObject" id-type="long">
<column name="objectClass" length="128" not-null="true"/>
<column name="objectId" not-null="true"/>
</any>
in one of my class mappings. So in my source tree I have:
com/galenworks/hibernate/DocumentCrossReference.java
com/galenworks/hibernate/hibernate-properties-DocumentCrossReference.xml
The hibernate-properties-DocumentCrossReference.xml contains the needed snippet. Pointing to the hibernate-properties-*.xml file in the hibernatedoclet mergedir and then running hibernatedoclet includes the snippet at the end of the class tag, ie.
Code:
<!-- =================================================================== -->
<!-- generates the hibernate HBM.XML files and SAR descriptor -->
<!-- =================================================================== -->
<target name="generate-Hibernate"
description="Generates Hibernate class descriptor files."
depends="compile">
<!-- copy additional resources for the Hibernate XDoclet task to the mergedir -->
<copy todir="${build.resources}/sar/hibernate">
<fileset dir="${src.dir}">
<include name="**/hibernate/hibernate-properties-*.xml"/>
</fileset>
</copy>
<!-- Execute the hibernatedoclet task -->
<hibernatedoclet
destdir="${build.resources}/sar/hibernate"
force="${xdoclet.force}"
mergedir="${build.resources}/sar/hibernate"
verbose="false">
<fileset dir="${src.dir}">
<include name="**/hibernate/*.java"/>
</fileset>
<hibernate version="2.0"/>
</hibernatedoclet>
</target>
Generates:
Code:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.galenworks.procedurelink.hibernate.DocumentCrossReference"
table="DocumentXref"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="documentXrefId"
column="documentXrefId"
type="long"
>
<generator class="sequence">
<param name="sequence">documentXrefSeq</param>
</generator>
</id>
<property
name="documentXPath"
type="string"
update="true"
insert="true"
column="documentXPath"
length="255"
not-null="true"
/>
[snip]
<!-- Included by Hibernate XDoclet task into the hbm.xml -->
<any name="referredToObject" id-type="long">
<column name="objectClass" length="128" not-null="true"/>
<column name="objectId" not-null="true"/>
</any>
</class>
</hibernate-mapping>