Member Menu
 
 Monthly JBoss newsletter:
 
Java Persistence with Hibernate
CaveatEmptor

XDoclet 2 for Hibernate 3

Note: This document reflects releases: Hibernate 3.0.5 and XDoclet 2. See http://www.hibernate.org/72.html for examples of what your model classes look like with XDoclet 1.x tags (which by-and-large are the same as XDoclet 2's tags), and http://www.hibernate.org/284.html for another developer's build.xml snippet (which doesn't use globbing). This page could/should be merged into that page, but it's not marked editable by guests.

Overview

XDoclet 2 was a rewrite of the XDoclet engine. It allows you to use Java5 language features in your model POJOs, and has substantially better error reporting than XDoclet 1. The XDoclet 2 developers unfortunately decided to make the collections tag names different from the XDoclet 1 tags, but the transition is an easy one-time recursive find/replace.

build-time libraries

My buildlib/ directory (that globs into my class.path) has:

ant-contrib-1.0b1.jar
commons-beanutils-1.7.0.jar
commons-collections-3.1.jar
commons-jelly-20050813.225330.jar
commons-jelly-tags-define-1.0.jar
commons-jelly-tags-jsl-1.0.jar
commons-jelly-tags-xml-20050823.222913.jar
commons-jexl-1.0.jar
commons-logging-1.0.4.jar
dom4j-1.6.jar
generama-1.2.1-SNAPSHOT.jar
jaxen-1.1-beta-4.jar
nanocontainer-1.0-beta-3.jar
nanocontainer-ant-1.0-beta-3.jar
picocontainer-1.0.jar
qdox-1.6-SNAPSHOT.jar
saxpath-1.0-FCS.jar
velocity-1.4.jar
xdoclet-2.0.3.jar
xdoclet-plugin-hibernate-1.0.2.jar

all which you will find in XDoclet 2's xdoclet2/distribution/lib/ (from following the download link at http://xdoclet.codehaus.org/ )

Build.xml setup

The documentation for XDoclet 2 is missing a fundamental issue--what to put into your ant buildfile. Note that you'll need to

1- define the class.path pathref

2- Make sure that "**model*.java" will find your model objects

3- decide where you want your .hbm files to go to (and set the hbm.dir property appropriately)

    <target name="hibernatedoclet"
        depends="init, compile"
        description="Generate Persistence and form classes">
        <taskdef
            name="xdoclet"
            classname="org.xdoclet.ant.XDocletTask"
            classpathref="class.path"
            />
        <xdoclet>
            <!-- defines the file handled by xdoclet2 -->
            <fileset dir="${src.java.dir}">
                <include name="**/model/*.java"/>
            </fileset>
            <!-- defines the processing of a plugin -->
            <component
                classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
                destdir="${hbm.dir}"
                version="3.0"
                />
        </xdoclet>
    </target>

Tag migration

For all your model classes, (non-regexp) replace "@hibernate.collection-" with "@hibernate."

Here's an example diff: http://cvs.photostructure.com/photostructure/src/java/com/photostructure/model/Label.java.diff?r1=1.5&r2=1.6


  NEW COMMENT

User this build.xml I got some error! 27 Feb 2006, 04:40 lzk
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE
PAGE!I have get error when use this build.xml


Buildfile: E:\eclipse\workspace\testa\build.xml
xdoclet2:
remove:
hibernate:
BUILD FAILED: E:\eclipse\workspace\testa\build.xml:100: Class Not Found:
Classloader URLs (classpath):
Total time: 1 second
 
Getting Class Not Found: Classloader URLs (classpath):exception 01 Mar 2006, 06:51 grogozinsky
Hi,
I've ran recently into the same exception while trying to generate 
hibernate mapping with xdoclet2. Were you able to solve it?

Thanks,
Galina.
 
Another example for XDOCLET ... 21 Apr 2006, 12:21 invizible
Hi, 
  I use XDOCLET to generate both hibernate.cfg.xml and *.hbm.xml 
files. Here is the ant target to do both. please free to change it 
accoridng to your needs. 

NOTE : change the "xdoclet.classpath" property based on your classpath

<target name="hibernate" depends="init-xdoclet" description="creates 
hibernate config file">
		<taskdef name="hibernatedoclet" 
classname="xdoclet.modules.hibernate.HibernateDocletTask" 
classpathref="xdoclet.classpath" />
		
		<hibernatedoclet 
excludedtags="@version,@author,@todo" 
			destdir="${build.dir}" 
			force="false" 
			verbose="true">

			<fileset dir="${java.dir}">
				<include name="**/*.java" />
			</fileset>
			<hibernate version="2.0" />
			<hibernatecfg
				dataSource="java:/OracleDS" 
			
	dialect="org.hibernate.dialect.OracleDialect" 
			
	jndiname="java:/hibernate/SessionFactory" 
			
	cacheProviderClass="org.hibernate.cache.EhCacheProvider" 
			
	transactionManagerStrategy="org.hibernate.transaction.JTATran
sactionFactory" 
			
	transactionManagerLookup="org.hibernate.transaction.JBossTran
sactionManagerLookup" >
				<otherProperty 
name="current_session_context_class" 
value="cdot.ctis.controller.ExtendedThreadLocalSessionContext" />
			</hibernatecfg>
		</hibernatedoclet>
	</target>
 
Re: Getting Class Not Found: Classloader URLs (classpath):except 06 Nov 2007, 12:31 expeditojr
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE
PAGE!On 01 Mar 2006 06:51, grogozinsky wrote:

>Hi,
>I've ran recently into the same exception while trying to generate
>hibernate mapping with xdoclet2. Were you able to solve it?

>Thanks,
>Galina.

Hi!

I've got the same error (Class Not Found). In my case, i've run my ant
build with -d -v arguments to see details about the error, so I saw that
the 'xdoclet-plugin-hibernate-1.0.3.jar' wasn't in my classpath. 

Hoppe it helps!
 
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]