21.16. Generating schema with Ant
<div class="paragraph">
If you would like to generate the database schema file with the Hibernate Tools Ant task, you simply need to use the
`org.hibernate.tool.ant.HibernateToolTask` to do so. This task will generate the definitions of all entities, both of
which are audited by Envers and those which are not.
</div>
<div class="paragraph">
For example:
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight">`<target name="schemaexport" depends="build-demo" description="Exports a generated schema to DB and file">
<taskdef
name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="build.demo.classpath"
/>
<hibernatetool destdir=".">
<classpath>
<fileset refid="lib.hibernate" />
<path location="${build.demo.dir}" />
<path location="${build.main.dir}" />
</classpath>
<jpaconfiguration persistenceunit="ConsolePU" />
<hbm2ddl
drop="false"
create="true"
export="false"
outputfilename="entities-ddl.sql"
delimiter=";"
format="true"
/>
</hibernatetool>
</target>`</pre>
</div>
</div>
<div class="paragraph">
Will generate the following schema:
</div>
<div class="listingblock">
<div class="content">
<pre class="prettyprint highlight">`create table Address (
id integer generated by default as identity (start with 1),
flatNumber integer,
houseNumber integer,
streetName varchar(255),
primary key (id)
);
create table Address_AUD (
id integer not null,
REV integer not null,
flatNumber integer,
houseNumber integer,
streetName varchar(255),
REVTYPE tinyint,
primary key (id, REV)
);
create table Person (
id integer generated by default as identity (start with 1),
name varchar(255),
surname varchar(255),
address_id integer,
primary key (id)
);
create table Person_AUD (
id integer not null,
REV integer not null,
name varchar(255),
surname varchar(255),
REVTYPE tinyint,
address_id integer,
primary key (id, REV)
);
create table REVINFO (
REV integer generated by default as identity (start with 1),
REVTSTMP bigint,
primary key (REV)
);
alter table Person
add constraint FK8E488775E4C3EA63
foreign key (address_id)
references Address;`</pre>
</div>
</div>
</div>
<div class="sect2">