Java Reference
In-Depth Information
The task shown in Listing B-2, which completes the simple example that we've been
building up in this section, creates a schema generation script from the annotation-based
mappings referenced in the project's hibernate.cfg.xml file.
Listing B-2. A Complete Hibernate Mapping Target
<target name="exportDDL" depends="compile">
<htools destdir="${sql}">
<annotationconfiguration
configurationfile="${src}/hibernate.cfg.xml"/>
<hbm2ddl
create="true"
drop="true"
format="true"
export="true"
outputfilename="${ant.project.name}.dll"/>
</htools>
</target>
The <hbm2cfgxml> element generates a Hibernate XML configuration file from the meta-
model information. Table B-4 shows the attributes that can be supplied.
Table B-4. The Attributes Available to the <hbm2cfgxml> Element
Property
Default
Description
destdir
If set, overrides, for this exporter only, the destination directory
specified on the tools task.
ejb3
false
By default, causes entities to be mapped using <mapping
resource="..."/> entries in the configuration file. If set to true , the
entities will be mapped using the <mapping class="..."/> approach to
pick up EJB 3 annotations in the mapped classes. This setting does not
cause a persistence.xml file to be generated!
Typically, the <hbm2cfgxml> element is used when the configuration task has been config-
ured from a properties fileā€”for example, when using <jdbcconfiguration> , you would typically
start with a normalized database schema and a properties file containing the connection details,
and use this exporter to create a hibernate.cfg.xml file containing both the connection details
and the details of the mapped entities.
The <hbm2java> element generates the Java source code for POJOs for each of the entities
held in the metamodel. Table B-5 shows the attributes that can be supplied.
Table B-5. The Attributes Available to the <hbm2java> Element
Property
Default
Description
destdir
If set, overrides, for this exporter only, the destination directory speci-
fied on the tools task
ejb3
false
If set to true , causes the POJOs to be generated with EJB 3 annotations
jdk5
false
If set to true , causes the POJOs to be generated with Java 5 constructs
(generics, enumerations, etc.)
Search WWH ::




Custom Search