Maven has a hibernate plugin, but it only does schema-export and something called aggregate mapping.
Aggregate mapping is better done using XDoclet's hibernatedoclet hibernatecfg subtask.
You need to do a number of things to get Maven, and then get XDoclet, and then setup XDoclet to run under maven ...
If you're not as familiar with Ant as you'd like I'd suggest using it first. Here's a section from a build.xml I wrote to generate and update my database(s). I have cvs HEAD version of Hibernate, which occurs in a directory called Hibernate2. Buidling it creates a parallel directory.
Code:
....
<path id="xdoclet.classpath">
<fileset dir="${xdoclet.lib.home}">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="hibernate.classpath">
<fileset dir="${hibernate.src.lib.home}" includes="**/*.jar"/>
<fileset dir="${hibernate.build.dir}" includes="**/*.jar"/>
</path>
....
<taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask">
<classpath>
<path refid="xdoclet.classpath"/>
<path refid="hibernate.classpath"/>
</classpath>
</taskdef>
<target name="hibernate" depends="prepare"
description="Generates the *.hbm.xml files, as well as the hibernate.cfg.xml file">
<hibernatedoclet
destdir="${hibernatedoclet.dest.dir}"
excludedtags="@version,@author,@todo"
force="false"
verbose="${hibernate.verbose}"
>
<fileset dir="${java.src.dir}">
<include name="**/*.java"/>
</fileset>
<hibernate version="2.0"/>
<hibernatecfg
jdbcUrl="jdbc:mysql://192.168.0.5:3306/ccgdb?autoReconnect=true"
dataSource="java:/comp/env/jdbc/ccgdb"
dialect="net.sf.hibernate.dialect.MySQLDialect"
driver="com.mysql.jdbc.Driver"
useOuterJoin="true"
userName="someuser"
password="somepassword"
showSql="true"
>
</hibernatecfg>
</hibernatedoclet>
</target>
<target name="schemaexport" depends="compile"
description="Generates SQL from our classes">
<taskdef name="schemaexport" classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
<classpath>
<path refid="hibernate.classpath"/>
<pathelement location="${build.classes.dir}"/>
<pathelement location="${hibernatedoclet.dest.dir}"/>
</classpath>
</taskdef>
<!--
output="${build.dir}/schema-export.sql">
-->
<schemaexport
properties="hibernate.connection.properties"
quiet="${schemaquiet}"
text="no"
drop="no"
delimiter=";">
<fileset dir="${hibernatedoclet.dest.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>
<target name="schemaupdate" depends="compile">
<taskdef name="schemaupdate" classname="net.sf.hibernate.tool.hbm2ddl.SchemaUpdateTask">
<classpath>
<path refid="hibernate.classpath"/>
<pathelement location="${build.classes.dir}"/>
<pathelement location="${hibernatedoclet.dest.dir}"/>
</classpath>
</taskdef>
<schemaupdate
properties="${basedir}/hibernate.connection.properties"
quiet="no">
<fileset dir="${hibernatedoclet.dest.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaupdate>
</target>
Note the section:
Quote:
Code:
<taskdef name="schemaexport" classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
<classpath>
<path refid="hibernate.classpath"/>
<pathelement location="${build.classes.dir}"/>
<pathelement location="${hibernatedoclet.dest.dir}"/>
</classpath>
</taskdef>
That's how I make sure the *.hbm.xml and *.class files they map are "next" to each other.