Java Reference
In-Depth Information
n Note Earlier versions of Hibernate Tools used the Velocity template language instead of FreeMarker, but
in other respects, they behaved in the same way.
If the existing exporters do not meet your needs, you can specify your own additional
code generation tasks using the <hbmtemplate> task. Table B-11 shows the attributes that can
be supplied to this task.
Table B-11. The Properties Available to the <hbmtemplate> Exporter Element
Property
Default
Description
destdir
If set, overrides, for this exporter only, the destination directory
specified on the Hibernate tool task.
exporterclass
Specifies a class to use to generate output. It will be invoked
once only, and the configuration object, output directory, tem-
plate path and prefix, and any configuration properties will be
passed into it.
filepattern
When using templates, represents the FreeMarker macro that
should be used to determine the file name for the entity being
processed.
template
Specifies the template to use to generate output. It will be invoked
for each of the entities in the configuration metamodel.
templatepath
Specifies the path from which your template(s) will be loaded,
overriding any default location.
templateprefix
Specifies an optional prefix to your template file name within
the template path. It is set by the standard tasks, so overriding
this allows you to import your own tasks instead.
Again, you have two options when carrying out this process. You can set the exporterclass
attribute to the name of the class to be used to carry out the export process. This class must
implement the org.hibernate.tool.hbm2x.Exporter interface. This is passed a reference to the
current configuration object and any other attributes that were set on the <hbmtemplate> task.
Alternatively, you can specify the name of a FreeMarker template to be used in processing
the configuration object and the name of a prefix.
<hbmtemplate
destdir="generated_txt"
templateprefix="foo"
template="template/MyTemplate.ftl"
filepattern="{package-name}/{class-name}.txt">
Note that filepattern contains FreeMarker macros that will be expanded at run time to
determine the appropriate file names for the tool's output. The task will search for this file on
the classpath, and then as a file resource.
If the configuration object does not contain some of the information that you need in
order to produce the desired output, you can also specify additional arbitrary details using
a standard Ant property or property set. Here's an example:
Search WWH ::




Custom Search