-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Tools and Ant HOWTO
PostPosted: Fri Nov 04, 2005 7:39 pm 
Newbie

Joined: Fri Nov 04, 2005 7:04 pm
Posts: 1
Location: Netherlands
Last couple days I spend some time to set up my ejb3.0 eclipse project. The most hard thing to realize was solving problem with ant classloader and conflicts when defining hibernatetools ant task.

Some common error messages found in debug mode are:
    java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    Type javax.persistence.Entity not present
    build.xml:38: Problems in creating a AnnotationConfiguration. Have you remembered to add it to the classpath ?
    org.apache.commons.logging.LogConfigurationException: Class org.apache.commons.logging.impl.Jdk14Logger does not implement Log

These are all result of conflicting of missing classpath entries. Also version conflicts in hibernate jars are possible. There was a bug in hibernate ant task impl's in using ClassLoader.

How to get this work:
If you have Eclipse 3.* installed and you also install hibernate tools (or JBoss IDE) you will try to use existing libraries to run ant scripts but … To get out of problems you have to get at least HibernateTools-3.1.0.beta1.zip.
1. Unzip HibernateTools-3.1.0.beta1.zip (don’t unzip it in eclipse directory, this is a step for later). In this example I used E:\Development\tools\hibernate-tools3.1.0beta1\
2. Define ant hibernatetools task in your ant script
Code:
   <property name="hib-tools.plugin" value="E:\Development\tools\hibernate-tools3.1.0beta1\plugins\org.hibernate.eclipse_3.1.0.beta1"></property>
   <path id="hibernatetools.path">
      <fileset dir="${hib-tools.plugin}\lib\tools" includes="hibernate-tools.jar" />
      <fileset dir="${hib-tools.plugin}\lib\hibernate" includes="hibernate3.jar" />
      <fileset dir="${hib-tools.plugin}\lib\hibernate" includes="commons-logging-1.0.4.jar" />      
      <fileset dir="${hib-tools.plugin}\lib\annotations" includes="hibernate-annotations.jar" />
      <fileset dir="${hib-tools.plugin}\lib\hibernate" includes="dom4j-1.6.1.jar" />
      <fileset dir="${hib-tools.plugin}\lib\annotations" includes="ejb3-persistence.jar" />
      <fileset dir="${hib-tools.plugin}\lib\hibernate" includes="commons-collections-2.1.1.jar" />
      <fileset dir="E:\development\eclipse\plugins\org.jboss.ide.eclipse.jdt.j2ee.core_1.5.0.M2\lib\j2ee-1.4" includes="jta-api.jar" />

      <fileset dir="${lib.dir}" includes="*.jar" />
   </path>
   <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="hibernatetools.path" > 
   </taskdef>
Where ${lib.dir} is folder where jdbc driver jar is stated.
3. Make hibernate.cfg.hbm (use hibernate plugin New -> Hiberante Configuration File)
4. Annotate you Entity classes with hibernates Entity annotation. Note is you are using EJB3.0 you already have javax.persistence.Entity annotation. You have to add hibernates Entity annotation to.
5. Define your target

Code:
   <target name="hib" >
      <hibernatetool destdir="hibernate" >
         <classpath>
            <path location="bin"></path>            
         </classpath>
         <annotationconfiguration  configurationfile="hibernate\hibernate.cfg.xml" />
         <hbm2ddl drop="false" outputfilename="dvd.sql" />
      </hibernatetool>
   </target>

That’s it.

Not yet tested: it would be nice to update hibernatetools distribution in you eclipse installation.

_________________
O Mrzljak
Be-value.nl


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 05, 2005 5:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
patches to the docs would be appreciated ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.