Java Reference
In-Depth Information
This task provides several subtasks, but in this chapter we will only make use of the
hbm2ddl subtask. This reads in the mapping and configuration files and generates Data Defini-
tion Language (DDL) scripts to create an appropriate schema in the database to represent our
entities.
Table 3-2 shows the basic directories that our build script assumes, relative to the exam-
ple project's root.
Table 3-2. The Project Directories
Directory
Contents
src
Source code and configuration files (excluding those directly related to the build)
bin
Compiled class files
sql
Generated DDL scripts
The root of the project contains the build script and build configuration file; it will also
contain the database files generated by HSQL when the exportDDL task is run.
The Ant Tasks
Table 3-3 shows the tasks contained in the Ant build script.
Table 3-3. The Tasks Available in the Example Ant Script
Task
Action
exportDDL
Creates the appropriate database objects. It also generates a script that can
be run against an HSQL database to re-create these objects if necessary.
compile
Builds the class files. This task is a dependency of all the tasks except
exportDDL (which does not require the class files), so it is not necessary to
invoke it directly.
populateMessages
Populates the database with a sample message.
listMessages
Lists all messages stored in the database by populateMessages .
createUsers
Creates a pair of users in the database for the Advert example.
createCategories
Creates a pair of categories in the database for the Advert example.
postAdverts
Creates several adverts in the database for the Advert example.
listAdverts
Lists the adverts in the database for the Advert example.
Enabling Logging
Before going on to run any of the examples in this chapter, you will want to create a
log4j.properties file in the classpath. A suitable example is provided with the Hibernate
tools in the etc directory of the unpacked archive.
Our example includes this file in the src directory of our project and places that direc-
tory itself on the classpath. In some circumstances—such as when building a JAR file for
inclusion in other projects—it may be better to copy the appropriate properties file(s) into
the target directory with the class files.
Search WWH ::




Custom Search