[EMAIL PROTECTED] wrote:
Hi Jose,
Thanks for your reply.
Quoting Jose Gonzalez Gomez <[EMAIL PROTECTED]>:
I've done this in several projects, so feel free to ask... I'm
sure if you're a bit more specific you'll get a lot of good tips from the
list.
Regarding hibernate tools; should i investigate the hibernate plugin to
generate the DDL (database schema) and javabeans from my mappings or
should i try to integrate my ant logic through the ant plugin (i think
this should be easy)? I heard the plugin is not mature enough.
Well, it has limited functionality (no update schema) but it's usable.
I must admit all my recent posts could be rephrased to "i am not yetRegarding hibernate/xdoclet... my maven.xml in a hibernate/xdoclet project:
familiar the directories maven uses, or when and how i should interrupt
the build process" and that translates to my problems figuring out
hibernate/xdoclet under maven. Sorry if this has RTFM written all over
it, i have been over the docs; it's just too much to absorb right away
and usually one learns better from an existing solution/best practice...
plus there just isn't enough time to do things the right way these days
(which is the main reason i want to use maven in the first place, to
both do things right and save time).
<!-- I must clean all those library tags, not all of them are needed :o) -->
<project default="jar" xmlns:j="jelly:core" xmlns:maven="jelly:maven" xmlns:ant="jelly:ant" xmlns:artifact="artifact">
<!-- This generates Hibernate mapping files just before compiling. -->
<preGoal name="java:compile">
<attainGoal name="xdoclet:hibernatedoclet"/>
</preGoal>
<!-- This is only useful if you need to use the generated schema elsewhere. -->
<postGoal name="jar:install">
<artifact:install artifact="${maven.build.dir}/schema/${pom.artifactId}-${pom.currentVersion}-schema.sql" type="schema" project="${pom}"/>
</postGoal>
<!-- I use this to force the copy of mapping files to the build directory. -->
<preGoal name="hibernate:schema-export">
<attainGoal name="jar:jar"/>
</preGoal>
<!-- ...and talking about missing update functionality. I guess it shouldn't be that dificult to add this to the plugin. -->
<goal name="myproject:update-schema" prereqs="jar:jar">
<ant:taskdef name="schemaupdate" classname="net.sf.hibernate.tool.hbm2ddl.SchemaUpdateTask">
<ant:classpath>
<ant:pathelement location="${maven.build.dest}"/>
<ant:path refid="maven.dependency.classpath"/>
</ant:classpath>
</ant:taskdef>
<ant:schemaupdate properties="hibernate.properties" quiet="no">
<ant:fileset dir="${maven.xdoclet.hibernatedoclet.destDir}"><ant:include name="**/*.hbm.xml"/></ant:fileset>
</ant:schemaupdate>
</goal>
</project>
In project properties:
# XDoclet - Hibernate properties
maven.xdoclet.hibernatedoclet.destDir=${maven.build.dir}/xdoclet/hibernatedoclet
maven.xdoclet.hibernatedoclet.hibernate.0.Version=2.0# Hibernate properties
maven.hibernate.properties=${basedir}/hibernate.properties
maven.hibernate.text=true
maven.hibernate.delimiter=;And from project.xml (don't know if some of those dependencies could be taken away, I did this a lot of time ago ;o)
<dependencies>
<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>2.1.6</version>
<properties>
<jar.manifest.classpath>true</jar.manifest.classpath>
</properties>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-full</artifactId>
<version>2.0.1</version>
<properties>
<jar.manifest.classpath>true</jar.manifest.classpath>
</properties>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.4</version>
<properties>
<jar.manifest.classpath>true</jar.manifest.classpath>
</properties>
</dependency>
<dependency>
<groupId>odmg</groupId>
<artifactId>odmg</artifactId>
<version>3.0</version>
<properties>
<jar.manifest.classpath>true</jar.manifest.classpath>
</properties>
</dependency>
<dependency>
<groupId>ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>0.7</version>
<properties>
<jar.manifest.classpath>true</jar.manifest.classpath>
</properties>
</dependency>
<dependency>
<groupId>xdoclet</groupId>
<artifactId>xjavadoc</artifactId>
<version>1.0.3</version>
<properties/>
</dependency>
<dependency>
<groupId>xdoclet</groupId>
<artifactId>xdoclet-hibernate-module</artifactId>
<version>1.2.2-SNAPSHOT</version>
<properties/>
</dependency>
<dependency>
<groupId>maven</groupId>
<artifactId>maven-hibernate-plugin</artifactId>
<version>1.2</version>
<type>plugin</type>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>7.4.1-jdbc3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
<!-- This is needed to get the mapping files copied to the resulting jar -->
<build>
<resources>
<resource>
<directory>${maven.xdoclet.hibernatedoclet.destDir}</directory>
<includes>
<include>**/*.hbm.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
And don't forget to create hibernate.properties:
hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect
I use to put all my domain classes in a subproject, so maven/xdoclet/hibernate do their magic and generate all the mapping files, and then, in the place where I use them (EJB layer, web layer, wherever) I put the generated jar as a dependency, and create a hibernate.cfg.xml in src/resources (or whatever your resources are) pointing to the database holding the data.
HTH, best regards Jose
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
