-->
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: SchemaExport task classpath nightmare
PostPosted: Fri Feb 13, 2004 10:46 am 
Newbie

Joined: Mon Oct 06, 2003 8:09 am
Posts: 1
Location: Dundee, Scotland
Hi...

I can't 'get' the SchemaExport task to 'find' my class files, and as a result it (the task) bombs out with a 'cannot find persistent class Foo'.

The class files are generated as a part of my Ant build and stored in the 'build' directory... the SchemaExport task doesn't seem to allow a classpathref to be passed to it, or indeed to have a classpath reference nested within it. The'build' directory ain't on the system classpath, and I don't want it to be. The generated mapping files get stored in the build directory right next to their persistent mapped class.

I have a kludgey workaround (see below), which copies all of the mapping files into the root of the build directory, exports the schema, and then deletes all of those temporarily copied mapping files... it works, but it seems a tad bent.

I have, to the best of my knowledge, RTFM, but I can't get the plain vanilla ant task def to generate these mappings. It's not a total disaster (since the hack below works), but can anyone shed any light on this?

I'm using Hibernate 2.1.

Code:
   <!--
   Initializes the database relations using the previously generated Hibernate mapping
   documents.
   -->
   <target name="db.generate-relations" description="Generates the database schema."
      depends="db.generate-mappings">

      <!--
     Make some temporary copies of the mapping files.
      -->
     <copy todir="${build.home}">
       <fileset dir="${build.home}" includes="**/*.hbm.xml" />
       <mapper type="flatten"/>
     </copy>

      <echo message="Creating the database schema."/>
      <java classname="net.sf.hibernate.tool.hbm2ddl.SchemaExport"
          fork="true">

         <jvmarg value="-Dhibernate.dialect=${db.dialect}"/>
         <jvmarg value="-Dhibernate.connection.driver_class=${db.driver}"/>
         <jvmarg value="-Dhibernate.connection.url=${db.url}${db.schema}"/>
         <jvmarg value="-Dhibernate.connection.username=${db.user}"/>
         <jvmarg value="-Dhibernate.connection.password=${db.password}"/>

         <arg line="${basedir}/${build.home}/*.hbm.xml"/>

         <classpath refid="build.classpath"/>
         <classpath>
            <pathelement location="${config.home}"/>
            <pathelement location="${build.home}"/>
         </classpath>
      </java>
     
      <!--
     Clean up the temporary mapping files created previously.
      -->
      <delete>
         <fileset dir="${build.home}" includes="*.hbm.xml"/>
     </delete>
   </target>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 1:20 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
How about:

Code:
        <taskdef name="schemaexport"
                 classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
            <classpath refid="hibernate.path"/>
            <classpath>
                <fileset dir="${build.lib}">
                    <include name="hibernateClasses.jar" />
                </fileset>
            </classpath>
        </taskdef>
                 
        <schemaexport output="${basedir}/${build.resources}/drop-and-build.sql"
                   properties="${hibernate.connection.config}"
                   quiet="yes"
                   delimiter=";"
                      text="yes">
            <fileset dir="${build.resources}/sar/hibernate">
                <include name="**/*.hbm.xml"/>
            </fileset>
        </schemaexport>


This chunk:

Code:
            <fileset dir="${build.resources}/sar/hibernate">
                <include name="**/*.hbm.xml"/>
            </fileset>


has hbm.xml files generated via XDoclet in folders with the class hierarchy.


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.