-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problems using hbm2ddl ant task and Hibernate 3 annotations
PostPosted: Wed Jul 27, 2005 12:00 pm 
Newbie

Joined: Wed Jul 27, 2005 11:47 am
Posts: 3
Location: Dortmund
Hi all,

I've a problem with using Hibernate 3 (with annotations) and the Hibernate ant task (from hibernate.tools.jar).

My ant task looks like that (snippet):

Code:
   <!-- Define paths -->
     <path id="class.path">
      <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
       </fileset>
     </path>

   <path id="hbn.path">
       <path refid="class.path"/>
      <fileset dir="${classes.dir}" />
   </path>

   <target name="hibernate" description="Generates the hibernate files.">
      <hibernatetool destdir="${basedir}" classpath="hbn.path">
         <annotationconfiguration configurationfile="${gen-src.dir}/hibernate.cfg.xml"/>
         <!-- SchemaExport based on Annotations -->
         <hbm2ddl drop="false" outputfilename="ddl/evalon_ddl.sql" />
        </hibernatetool>
   </target>



Mapping documents:
Code:
<hibernate-configuration>
   <session-factory>

      <!-- hibernate properties -->
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost/hbn2oaw</property>
      <property name="hibernate.connection.username">webshop_user</property>
      <property name="hibernate.connection.password">webshop_user</property>
      <property name="hibernate.connection.pool_size">5</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="show_sql">true</property>
      <property name="use_outer_join">false</property>

      <!-- mapping -->

      <mapping class="net.sf.evalon.entity.Person" />


   </session-factory>
</hibernate-configuration>



Ant output (on Eclipse console):
Code:
Buildfile: E:\Fachhochschule\Projektarbeit\EvalOn\build.xml
Overriding previous definition of reference to class.path
hibernate:
[hibernatetool] Executing org.hibernate.tool.ant.Hbm2DDLGeneratorTask@1eb2c1b
[hibernatetool] 27.07.2005 17:54:19 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: Hibernate 3.0.3
[hibernatetool] 27.07.2005 17:54:19 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: hibernate.properties not found
[hibernatetool] 27.07.2005 17:54:19 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: using CGLIB reflection optimizer
[hibernatetool] 27.07.2005 17:54:19 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: using JDK 1.4 java.sql.Timestamp handling
[hibernatetool] 27.07.2005 17:54:19 org.hibernate.cfg.Configuration configure
[hibernatetool] INFO: configuring from file: hibernate.cfg.xml

BUILD FAILED
E:\Fachhochschule\Projektarbeit\EvalOn\build.xml:103: org.hibernate.MappingException: Unable to load class declared as <mapping class="net.sf.evalon.entity.Person"/> in the configuration:


After trying for some hours I'm still not able to find out what I did wrong?

I just followed the instructions from the documentation...
(http://www.hibernate.org/hib_docs/tools/ant/index.html)

Greets,
Christian
(still hoping that someone is able to help him :)!)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2005 2:49 pm 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
SchemaExport based on annotations need .class files. Are you sure you compile your classes before running schemaexport? I don't see that your ant target "hibernate" has any dependency on "compile" target.


Top
 Profile  
 
 Post subject: Re: Problems using hbm2ddl ant task and Hibernate 3 annotati
PostPosted: Wed Jul 27, 2005 3:32 pm 
Newbie

Joined: Wed Jul 27, 2005 11:47 am
Posts: 3
Location: Dortmund
Hi,

yes, there's a compile task running before my hibernate task. I just posted a snippet :).

huelsmeier wrote:
My ant task looks like that (snippet):


Well, here is my complete build file. Maybe this helps more to help me :).

Code:
<project basedir="." default="buildwar" name="EvalOn4Tomcat">

   <!-- load properties from file -->
   <property file="build.properties"/>
   
   <!-- define properties -->
     <property name="src.dir"        value="${basedir}/base-src"/>
     <property name="gen-src.dir"    value="${basedir}/src"/>
     <property name="classes.dir"    value="${basedir}/bin"/>
     <property name="lib.dir"        value="${basedir}/lib" />
     <property name="webinf.dir"     value="${basedir}/WEB-INF"/>
   <property name="htdocs.dir"     value="${basedir}/htdocs"/>
   <property name="build.dir"      value="${basedir}/build"/>
   <property name="dist.dir"       value="${basedir}/dist"/>

   <property name="war.name"      value="evalon.war" />

   <taskdef
        name="hibernatetool"
        classname="org.hibernate.tool.ant.HibernateToolTask"
       classpathref="class.path" />
      
   <!-- Define paths -->
     <path id="class.path">
      <fileset dir="${lib.dir}">
            <include name="**/*.jar"/>
       </fileset>
     </path>

   <path id="hbn.path">
       <path refid="class.path"/>
      <fileset dir="${classes.dir}" />
   </path>
   
   <path id="src.path">
      <fileset dir="${src.dir}">
         <include name="**/*.java"/>
      </fileset>
      <fileset dir="${gen-src.dir}">
         <include name="**/*.java"/>
      </fileset>
   </path>

   <target name="compile" description="Compiles the sources." >
       <delete dir="${classes.dir}" />
       <mkdir  dir="${classes.dir}"/>
       <javac destdir="${classes.dir}"
              classpathref="class.path"
              debug="on"
              deprecation="on"
              optimize="off">
         <src path="${src.dir}"/>
        <src path="${gen-src.dir}"/>
       </javac>
   </target>

   <target name="prepare" depends="compile" description="Prepares the war-build buy generating a tmp-dir and copying the compiles data.">
       <!-- make directories -->
       <delete dir="${build.dir}" />
       <mkdir dir="${build.dir}"/>
       <mkdir dir="${build.dir}/WEB-INF" />
       <!--mkdir dir="${build.dir}/WEB-INF/src" /-->
       <mkdir dir="${build.dir}/WEB-INF/classes" />

       <delete dir="${dist.dir}" />
       <mkdir dir="${dist.dir}"/>
      <!-- copy jsp-Sites -->
       <copy todir="${build.dir}" includeemptydirs="true">
          <fileset dir="${htdocs.dir}">
              <include name="**/*.*"/>
             <exclude name=".*.jsp" />
           </fileset>
       </copy>
       <!-- copy web-information -->
       <copy todir="${build.dir}/WEB-INF" includeemptydirs="true">
          <fileset dir="${webinf.dir}">
              <include name="**/*.*"/>
          </fileset>
       </copy>
       <!-- copy classes -->
       <copy todir="${build.dir}/WEB-INF/classes" includeemptydirs="true">
           <fileset dir="${classes.dir}">
               <include name="**/*.*"/>
           </fileset>
       </copy>
       <!-- copy properties -->
       <copy todir="${build.dir}/WEB-INF/classes" includeemptydirs="true">
            <fileset dir="${src.dir}">
              <include name="*.properties"/>
          </fileset>
       </copy>
      <!-- copy libraries -->
      <copy todir="${build.dir}/WEB-INF/lib" includeemptydirs="true">
         <fileset dir="${lib.dir}">
            <include name="commons-*.jar" />
            <include name="struts.jar" />
            <include name="jakarta-oro.jar" />
         </fileset>
      </copy>
   </target>
   
   <target name="hibernate" description="Generates the hibernate files.">
      <hibernatetool destdir="${basedir}" classpath="hbn.path">
         <annotationconfiguration configurationfile="${gen-src.dir}/hibernate.cfg.xml"/>
         <!-- SchemaExport based on Annotations -->
         <hbm2ddl drop="false" outputfilename="ddl/evalon_ddl.sql" />
        </hibernatetool>
   </target>

     <target name="buildwar" depends="prepare, hibernate" description="Builds war file in the temp-directory" >
        <war basedir="${build.dir}" destfile="${dist.dir}/${war.name}"  webxml="${build.dir}/WEB-INF/web.xml" includes="**/*.*" />
     </target>

</project>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 27, 2005 5:54 pm 
Newbie

Joined: Wed Jul 27, 2005 5:38 pm
Posts: 13
Location: Colorado, USA
Hi,

I think your
Quote:
<path id="hbn.path">
<path refid="class.path"/>
<fileset dir="${classes.dir}" />
</path>


is to blame.

Try instead to use this;

Quote:
<path id="hbn.path">
<path refid="class.path"/>
<path location="${classes.dir}" />
</path>


I think what is happening is that fileset is creating a group of .class files where the classpath entry needs the top level directory that contains net.sf.evalon.* classes.

Hope this helps.

-bd-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 3:43 am 
Newbie

Joined: Wed Jul 27, 2005 11:47 am
Posts: 3
Location: Dortmund
No, that doesn't work. :(
I also tried to build a jar file including my class files and add it to the classpath which didn't work.

Does anyone did ever do the same I'm trying to do: creating a ddl out of mapping information contained in annotations?
Maybe he/she is willing to post his solution if it works?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 4:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
try to use the latest version of tools from cvs if possible - we had a fix regarding classloading in this area.

_________________
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.  [ 6 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.