Java Reference
In-Depth Information
<hbmtemplate …>
<property key="bar" value="BAR!"/>
</hbmtemplate>
In addition to any properties you add to the template task yourself, you will have access to
the scripting variables listed in Table B-12.
Table B-12. The Standard Scripting Variables Available to a Template Task
Variable
Description
artifacts
An instance of org.hibernate.tool.hbm2x.ArtifactCollector that can be pop-
ulated with values to reflect the actions taken during output generation
c2h
An instance of the org.hibernate.tool.hbm2x.Cfg2HbmTool class providing
helper methods for converting configuration object values into Hibernate
mapping files
c2j
An instance of the org.hibernate.tool.hbm2x.Cfg2JavaTool class providing
helper methods for converting configuration object values into Java class files
cfg
A reference to the configuration object
outputdir
The path specified as the <hbmtemplate> element's destdir attribute
template_path
A list of the paths to directories containing FreeMarker templates
The standard Hibernate Tools exporter tasks are implemented in much the same way.
Although we haven't shown this when discussing their attributes earlier, all the exporter tasks
support the templatepath and templateprefix attributes, allowing you to override their default
behavior by instructing them to use a different set of FreeMarker macros than those included
in the hibernate-tools.jar file. All attributes also support the use of property sets to pass in
information that is required by your custom macros but isn't available from the configuration
object.
A very simple FreeMarker script is shown in the following code. This is not very useful in
itself, as the first four variables simply display their hashcode representations from the default
toString() implementation, but it provides you with a syntactically valid starting point for
exploration of the code generation tools.
Configuration object: ${cfg}
Artifacts object: ${artifacts}
Cfg2Hbm Helper: ${c2h}
Cfg2Java Helper: ${c2j}
Output Directory: ${outputdir}
Template path: ${template_path[0]}
Configuring the Classpath
There are two distinct classpaths to consider when setting up the Hibernate Tools Ant tasks:
the classpath of the task definition , and the classpath to be used by the tasks . The task defini-
tion needs to have in its classpath the Hibernate Tools JAR file, the Hibernate libraries, the
Hibernate Annotations libraries, and the JDBC driver that will be used to access the database.
A typical configuration of this classpath is as follows:
Search WWH ::




Custom Search