i don't use reverseenginer.
here is a template i made for the middlegen hibernate task
Code:
package ${table.package};
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
#set ($pkg = $table.package)
/**
*
* @author
* @hibernate.class table="${table.getSqlName()}"
*
**/
public class ${table.destinationClassName} implements Serializable {
#set ($KeyIdFlag = true)
#set ($VersionId = true)
#set ($haspk = false)
#foreach( $column in $table.basicColumns )
#if ($column.pk)
#set ($haspk = true)
#end
private ${column.javaType} ${column.variableName};
#end
#if (!$haspk)
//it don't have a pk
#foreach( $column in $table.columns )
#if (!$haspk && $column.fk)
#set ($haspk = true)
private ${column.javaType} ${column.variableName};
/**
* Standard getter
* @return ${column.variableName}
* @hibernate.id type="$column.javaType" column="$column.sqlName" generator-class="sequence"
* @hibernate.generator-param name="sequence" value="${column.sqlName}_seq"
**/
public ${column.javaType} ${column.getGetterName()}() {
return this.${column.variableName};
}
#end
#end
#end
#foreach( $column in $table.basicColumns )
#set ($CompositeKeyFlag = false)
#if ($column.pk)
#set ($haspk = true)
#if ($KeyIdFlag && $table.compositeKey)
#set ($KeyIdFlag = false)
#set ($CompositeKeyFlag = true)
//<composite-id name="comp_id" class="${table.package}.${table.compoundKeyDestinationClassName}">
#foreach ( $compKeysClass in $table.primaryKeyColumns )
//<key-property name="${compKeysClass.variableName}" column="${compKeysClass.sqlName}" />
#end
//</composite-id>
#elseif ($KeyIdFlag)
/**
* Standard getter
* @return ${column.variableName}
* @hibernate.id type="$column.javaType" column="$column.sqlName" generator-class="sequence"
* @hibernate.generator-param name="sequence" value="${column.sqlName}_seq"
**/
public ${column.javaType} ${column.getGetterName()}() {
return this.${column.variableName};
}
/**
* Standard setter
*
**/
public void ${column.getSetterName()}(${column.javaType} inval) {
this.${column.variableName} = inval;
}
#end
#if ($table.versioningPresent && $VersionId)
#set ($VersionId = false)
#set ($versionCol = $table.versioningField)
#if ($versionCol.specialtyVersionProperty)
<version
name="${versionCol.variableName}"
type="$versionCol.javaType"
column="$versionCol.sqlName"
/>
#elseif ($versionCol.specialtyTimestampProperty)
<timestamp
name="${versionCol.variableName}"
column="$versionCol.sqlName"
/>
#end
#end
#else
#if ($column.specialtyProperty)
/**
*
* Standard getter
* @return ${column.variableName}
* @hibernate.property type="$column.javaType"
* column="$column.sqlName"
#if (!$column.nullable)
* not-null="true"
#end
#if ($column.unique)
* unique="true"
#end
#if ($column.sized)
* length="$column.size"
#end
*
**/
public $column.javaType ${column.getGetterName()} () {
return this.${column.variableName};
}
/**
* Standard setter
*
**/
public void ${column.getSetterName()}(${column.javaType} inval) {
this.${column.variableName} = inval;
}
#end
#end
#end
#foreach($relationshipRole in $table.relationshipRoles)
#if( $relationshipRole.enabled )
#set( $one2one = $relationshipRole.relation.one2One )
#set( $many2many = $relationshipRole.relation.many2Many )
#set( $bidirectional = $relationshipRole.relation.bidirectional )
#set( $target = $relationshipRole.getTarget($plugin))
########## Compute cardinality strings for javadocs (useful for humans)
#if( $bidirectional )
#set( $directionalityText = "bi-directional" )
#else
#set( $directionalityText = "uni-directional" )
#end
#if( $many2many )
#set( $cardinalityText = "many-to-many" )
#else
#if( $one2one )
#set( $cardinalityText = "one-to-one" )
#else
#if($relationshipRole.targetMany)
#set( $cardinalityText = "one-to-many" )
#else
#set( $cardinalityText = "many-to-one" )
#end
#end
#end
// $directionalityText $cardinalityText association to $target.destinationClassName
#if( !$relationshipRole.targetMany )
#if( $one2one )
private ${target.package}.${target.destinationClassName} $table.getVariableName($relationshipRole);
/**
*
* Standard getter
*
* @hibernate.one-to-one class="${table.getVariableName($relationshipRole)}" outer-join="auto"
#if ($bidirectional)
* not-null="true"
#end
*
**/
public ${target.package}.${target.destinationClassName} $table.getGetterName($relationshipRole)() {
return this.$table.getVariableName($relationshipRole);
}
public void $table.getSetterName($relationshipRole)(${target.package}.${target.destinationClassName} invar) {
this.$table.getVariableName($relationshipRole) = invar;
}
#else
private ${target.package}.${target.destinationClassName} $table.getVariableName($relationshipRole);
/**
*
* Standard getter
#set ($name = "${table.getVariableName($relationshipRole).substring(0,1).toUpperCase()}${table.getVariableName($relationshipRole).substring(1)}")
* @hibernate.one-to-one class="${table.package}.${name}" outer-join="auto"
#if ($bidirectional)
* not-null="true"
#end
#foreach( $columnMap in $relationshipRole.targetRole.columnMaps )
* column name="$columnMap.foreignKey
#end
*
**/
public ${target.package}.${target.destinationClassName} $table.getGetterName($relationshipRole)() {
return this.$table.getVariableName($relationshipRole);
}
/**
*
* Standard setter
*
**/
public void $table.getSetterName($relationshipRole)(${target.package}.${target.destinationClassName} invar) {
this.$table.getVariableName($relationshipRole) = invar;
}
#end
#else
#if( !$many2many && $bidirectional )
#foreach($relRole in $target.relationshipRoles)
#if( $relRole.target.getSqlName() != $table.getSqlName() )
#set ($name = "${relRole.target.getSqlName().substring(0,1).toUpperCase()}${relRole.target.getSqlName().substring(1)}")
#set ($rl = $relRole.target.getSqlName())
#set ($col = $relRole.target.getPkColumn().getSqlName())
#end
#end
#foreach ($column in $target.basicColumns)
#if ($column.pk == false)
#set ($sortcol = $column.sqlName)
#end
#end
#end
private java.util.List $rl;
/**
*
* Standard getter
*
* @hibernate.list lazy="true" table="${target.getSqlName()}" role="${rl}s"
* @hibernate.collection-many-to-many column="${col}" class="${pkg}.${name}"
* @hibernate.collection-key column="${table.getPkColumn().getSqlName()}"
* @hibernate.collection-index column="$sortcol"
*
*
**/
public java.util.List get${name}s() {
return this.${rl};
}
/**
*
* Standard setter
* @param inval
**/
public void set${name}s( java.util.List inval ) {
this.$rl = inval;
}
private java.util.Set $table.getVariableName($relationshipRole);
/**
*
* Standard getter
*
#if( !$many2many && $bidirectional )
#set ($name = "${table.getVariableName($relationshipRole).substring(0,1).toUpperCase()}${table.getVariableName($relationshipRole).substring(1)}")
* @hibernate.set lazy="true" inverse="true" cascade="none" role="${table.getVariableName($relationshipRole)}" table="${target.getSqlName()}"
* @hibernate.collection-key column="${table.getPkColumn().getSqlName()}"
* @hibernate.collection-one-to-many class="${target.package}.${target.destinationClassName}"
#end
#if( $many2many )
* table="$relationshipRole.relation.joinTable.sqlName"
#end
**/
public java.util.Set $table.getGetterName($relationshipRole) () {
return this.$table.getVariableName($relationshipRole);
}
/**
*
* Standard setter
*
**/
public void $table.getSetterName($relationshipRole) (java.util.Set invar) {
this.$table.getVariableName($relationshipRole) = invar;
}
#end
#end
#end
#foreach( $column in $table.basicColumns )
#if ($column.pk)
/**
*
* Equals test
* @returns true if the object passed in equals this object
*
**/
public boolean equals(Object other) {
if (!(other instanceof ${table.destinationClassName}))
return false;
${table.destinationClassName} castOther = (${table.destinationClassName}) other;
return new EqualsBuilder().append(this.$column.variableName, castOther.$column.variableName).isEquals();
}
/**
* Custom hashcode function uses the pk field.
* @returns int hashcode
*
**/
public int hashCode() {
return new HashCodeBuilder().append($column.variableName).toHashCode();
}
#end
#end
}
copy that template code to a file named hibernate_java.vm
then you have an ant task like this for middlegen
Code:
<target
name="middlegen"
description="Run Middlegen"
unless="middlegen.skip"
depends="check-driver-present,panic-if-driver-not-present,del"
>
<taskdef
name="middlegen"
classname="middlegen.MiddlegenTask"
classpathref="lib.class.path"
/>
<middlegen
appname="${name}"
prefsdir="${src.dir}"
gui="${gui}"
databaseurl="${database.url}"
initialContextFactory="${java.naming.factory.initial}"
providerURL="${java.naming.provider.url}"
datasourceJNDIName="${name}.database"
driver="${database.driver}"
username="${database.userid}"
password="${database.password}"
schema=""
>
<hibernate
destination="${build.gen-src.dir}"
package="${project-package}.${name}">
<fileproducer
template="${basedir}/src/templates/hibernate_java.vm"
destination="${build.gen-src.dir}"
filename="{0}.java"/>
</hibernate>
</middlegen>
</target>
You will have to play with middlegen api a bit, but it's working really nice for me right now. Generates all the java source files with xdoclet tags. To get your hibernate.hbm.xml files you need to run another ant target. The hibernatedoclet target looks like this (from hibernate docs and xdoclet)
Code:
<target name="hibernate" description="Generate mapping documents (run jar first)">
<taskdef
name="hibernatedoclet"
classname="xdoclet.modules.hibernate.HibernateDocletTask"
classpathref="xdoc.lib"
/>
<taskdef
name="xdoclet"
classname="xdoclet.DocletTask"
classpathref="xdoc.lib"
/>
<echo>+---------------------------------------------------+</echo>
<echo>| |</echo>
<echo>| R U N N I N G H I B E R N A T E D O C L E T |</echo>
<echo>| |</echo>
<echo>+---------------------------------------------------+</echo>
<hibernatedoclet
destdir="${build.gen-src.dir}"
mergedir="${build.gen-src.dir}"
excludedtags="@version,@author,@todo,@see"
addedtags="@xdoclet-generated at ${TODAY},@copyright The XDoclet Team,@author XDoclet,@version ${version}"
force="true"
verbose="false">
<fileset dir="${build.gen-src.dir}">
<include name="**/*.java"/>
</fileset>
<hibernate version="2.0"/>
</hibernatedoclet>
<replace dir="${build.gen-src.dir}">
<include name="**/*.hbm.xml"/>
<replacefilter token="readonly" value="inverse"/>
<replacefilter token="role" value="name"/>
<replacefilter token="hibernate-mapping.dtd" value="hibernate-mapping-2.0.dtd"/>
</replace>
</target>
Hope that helps