O/R mapping plugin; generates hibernate mappings and exports a database schema. More...
| Release-level Ant targets: | |
|---|---|
| hibernate-schemaexport | Run this task to generate a "mainmodule/build/schema/schema.sql" file
based on the output of "hibernate-generatemapping" of all modules. This
task assumes there is a "resources/conf/hibernate.properties" or a
"resource/conf/hibernate.cfg.xml" in the module with type
main.
|
| hibernate-createcfg |
Creates a hibernate.cfg.xml file containing all generated '.hbm' files in the '@antmod.hibernate.cfg.xml.mappings@' variable.
See Hibernate configuration
for full information.
Events intercepted: build-post.
|
| Module-level Ant targets: | |
|---|---|
| hibernate-generatemapping | Not intended to be invoked directly. Generates ".hbm" files based on
xdoclet hibernate javadoc tags into
"${antmod.hibernate.generatemapping.destdir}". Is automatically
executed as part of the "build" target, provided that
${antmod.hibernate.generatemapping.enabled} is set to true.
Events intercepted: javac-post.
|
| Configurable properties: [...] | |
|---|---|
| antmod.hibernate.generatemapping.enabled | If true, ".hbm" files are generated automatically. Defaults to
false. |
| antmod.hibernate.generatemapping.destdir | The directory where the ".hbm" files are generated. Defaults to
${antmod.module.dirs.build.classes}. |
| antmod.hibernate.generatemapping.excludedtags | The javadoc tags that should not be automatically written to output files. Defaults to "@version,@author,@todo". |
| antmod.hibernate.generatemapping.force | Specify if the generation of ".hbm" files should be forced, which always
causes regeneration even if nothing changed. Defaults to
false. |
| antmod.hibernate.generatemapping.mergedir | Directory where subtasks will look for files to be merged with generated
files. Defaults to ${antmod.module.dirs.build.classes}. |
| antmod.hibernate.generatemapping.verbose | If true verbose output of the ".hbm" generation will be
generated. Defaults to false. |
| antmod.hibernate.generatemapping.includes | Specifies a filter specifying the java source files that should be checked
for hibernate xdoclet javadoc tags. This is relative to the
${antmod.module.dirs.src.java} directory. Defaults to
"**/*.java" |
| antmod.hibernate.generatemapping.version | The hibernate version you want to generate mappings for. Defaults to "2.0". |
| antmod.hibernate.config | The location of the preferred 'hibernate.cfg.xml' file inside the
main module. Defaults to
${antmod.module.dirs.resources}/conf/hibernate.cfg.xml. |
| antmod.hibernate.schemaexport.properties | If no ${antmod.hibernate.config} file is found, this 'hibernate.properties'
file inside the main module is used. Defaults to
${antmod.module.dirs.resources}/conf/hibernate.properties. |
| antmod.hibernate.schemaexport.src | Does not apply when using 'hibernate.cfg.xml': The directory containing the
".hbm.xml" used as input for generating the SQL schema. Defaults to
. (basedir of the release). |
| antmod.hibernate.schemaexport.src.includes | Does not apply when using 'hibernate.cfg.xml': Comma-separated list of
patterns of Hiberante mapping files, which will be included during
generation process. Defaults to
*/${antmod.hibernate.generatemapping.destdir}/**/*.hbm.xml. |
| antmod.hibernate.schemaexport.src.excludes | Does not apply when using 'hibernate.cfg.xml': Comma-separated list of patterns of Hiberante mapping files, which will be excluded during generation process. By default this is empty. |
| antmod.hibernate.schemaexport.destdir | The directory in the main module where the DDL SQL schema is
generated to. Defaults to
${antmod.module.dirs.build}/schema. |
| antmod.hibernate.schemaexport.output | The name of the file which is created inside the main module
and will contain the generated DDL SQL schema. Defaults to
${antmod.hibernate.schemaexport.destdir}/schema.sql. |
| antmod.hibernate.schemaexport.quiet | Make the output be verbose or not while exporting the schema. Defaults to
false. |
| antmod.hibernate.schemaexport.text | If true the export goes to text, otherwise directly into the database.
Defaults to true. |
| antmod.hibernate.schemaexport.drop | If true the exported schema will only drop all existing
tables and data, based on the mapping files. Best thing is to set this as
system property on the command-line if needed, and never set it as a
property. Defaults to false. |
| antmod.hibernate.schemaexport.delimiter | Delimiter used in generated schema. Defaults to ";". |
This plugin handles the generation of Hibernate mapping files as part of the "build" target, as well as the exporting of the schema to a ".sql" file.
Hibernate is the most popular O/R mapping mechanism for Java projects, read more at http://www.hibernate.org/.
The hibernate plugin will generate the ".hbm" files (the hibernate mapping
files) based on the javadoc tags that are in the source files: this is based on
xdoclet's hibernate
doclet. The ".hbm" files are generated in the
${antmod.hibernate.generatemapping.destdir} directory, and will
automatically end up in the jar file of the module that is put in the
classpath.
The end result is that the java sources become the single source for both the object definition, and the way it is mapped to the database. The antmod hibernate plugin takes care of automatically generating the mapping files (usin xdoclet), and making them available during runtime.
This plugin always tries to locate a 'hibernate.cfg.xml' in the
"resources/conf" directory of the main module (can be configured
using ${antmod.hibernate.config}).
If a 'hibernate.cfg.xml' is not found, the hibernate-schemaexport
target will fall back to "resources/conf/hibernate.properties" in the
main module.
So when using "hibernate.cfg.xml", commit it in the "resources/conf" directory
of the main module. Next, if
${antmod.hibernate.generatemapping.enabled} is set to true for the
release, "ant build" on release level can automatically fill in all
available mappings in the 'hibernate.cfg.xml'. This prevents you from
having to manually enter each ".hbm.xml" that has been generated automatically
by this plugin's hibernate-generatemappings.
What happens is that the token "@antmod.hibernate.cfg.xml.mappings@" is replaced with the actual mappings that are found in each module. Now, a typical 'hibernate.cfg.xml' looks like this:
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE
hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration> <session-factory> <property
name="connection.datasource">java:comp/env/jdbc/name</property>
<property name="show_sql">true</property> <property
name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
<!-- Mapping file XML list, generated by Antmod -->
@antmod.hibernate.cfg.xml.mappings@ </session-factory>
</hibernate-configuration>