Java Reference
In-Depth Information
In principle, the <query> element allows you to specify an arbitrary HQL query that will be
run against the database using the configuration's mapping information. Table B-9 shows the
attributes that can be supplied.
Table B-9. The Properties Available to the <query> Exporter Element
Property
Default
Description
destdir
If set, overrides, for this exporter only, the destination directory specified
on the tools task.
destfile
If set, specifies the file into which the output of the queries will be writ-
ten. If left unset, the query is carried out, but the output is not saved.
The HQL query itself is included as the body of the <query> element .
<query destdir="output" destfile="sql.log">
select n.owner from Notepad n
</query>
If you want to include multiple SQL queries in the task, you can include multiple nested
<hql> elements thus:
<query destdir="output" destfile="sql.log">
<hql>select n.owner from Notepad n</hql>
<hql>select n.owner from Note n</hql>
</query>
Reverse Engineering
As we discussed in the previous section, the <jdbcconfiguration> task can be used to create
a configuration metamodel directly from a database schema. However, a database schema is
not necessarily an exact match for the entity mappings that we want to create. It may contain
tables and columns that we would prefer to omit from our entities. It may also lack some of
the information that we want to express. For example, database types such as VARCHAR do not
map exactly to Java types such as char[] and java.lang.String , and the tables will have names
that do not conform to the Java naming conventions.
Used as is, the <jdbcconfiguration> task will select sensible defaults for the type names,
and will assign the reverse-engineered tables suitable Java names derived from the table
names. It also provides an attribute to allow you to directly specify a suitable package name.
Even so, we would really like more control over the specifics of the reverse engineering process.
Note that while it also provides a naming strategy attribute, this has no effect during the reverse
engineering process, as naming strategy classes can only be used to determine schema names
from mapping information, not vice versa.
Hibernate provides two ways in which this process can be controlled—you can specify
one of two attributes on the <jdbcconfiguration> task to override the default behavior.
Search WWH ::




Custom Search