-->
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.  [ 9 posts ] 
Author Message
 Post subject: Ant Tools: Resource not found
PostPosted: Mon Jul 11, 2005 5:05 am 
Newbie

Joined: Mon Jul 11, 2005 4:27 am
Posts: 5
Hi all,

I'm a newbie with both Hibernate and Ant and am trying to run the tools hbm2java and hbm2ddl with Hibernate 3 and an Oracle 9 Database on a WinXP machine.

My ANT buildfile is the following:
Code:
<project name="HibernateTest" default="gencode" basedir=".">
    <description>
        test build file for hibernate test
    </description>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
  </target>

  <taskdef
     name="hibernatetool"
     classname="org.hibernate.tool.ant.HibernateToolTask">
    <classpath>
      <pathelement path="${classpath}"/>
      <fileset dir="E:\Java\Hibernate-3.0.5\hibernate-3.0\lib">
        <include name="**/*.jar"/>
      </fileset>
      <fileset dir="E:\Java\Eclipse 3.1\eclipse\plugins\org.hibernate.eclipse_3.0.0.alpha4\lib">
        <include name="**/*.jar"/>
      </fileset>
      <pathelement location="E:\Java\Hibernate-3.0.5\hibernate-3.0\hibernate3.jar"/>
      <pathelement path="E:\Java\Hibernate-3.0.5\hibernate-3.0\etc"/>
    </classpath>
  </taskdef>

  <target name="gencode">
    <hibernatetool destdir="[output dir]">
     
     <configuration configurationfile="hibernate.cfg.xml" >
      <fileset dir="E:\Java\Hibernate-3.0.5\hibernate-3.0" id="config_fileset">
        <include name="**/*.hbm.xml"/>
      </fileset>
     </configuration>

     <hbm2java/>
    </hibernatetool>
  </target>
     
  <target name="genshema">
    <hibernatetool destdir="[output dir]">
     
     <configuration configurationfile="hibernate.cfg.xml" >
      <fileset dir="E:\Java\Hibernate-3.0.5\hibernate-3.0" id="config_fileset">
        <include name="**/*.hbm.xml"/>
      </fileset>
     </configuration>

     <hbm2ddl drop="false" outputfilename="Zonentarif.sql"/>
    </hibernatetool>
  </target>
     
</project>


My config file:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@mymachine:1521:mydb</property>
        <property name="connection.username">dbuser</property>
        <property name="connection.password">dbpwd</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>

        <mapping resource="test\Zonentarif.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

(DB-machine, instance, user and pwd substituted with placeholders for display purposes)

My resource mapping in the appropriate subfolder test looks like this:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
   package="test">

   <import class="Zonentarif"/>

   <class name="Zonentarif">
      <comment>Zonentarif</comment>
      
      <id name="id">
         <generator class="native"/>
      </id>
      
      <natural-id>
         <many-to-one name="gewKlasseID"/>
         <property name="vonZoneID"/>
         <property name="nachZoneID"/>
      </natural-id>
   </class>
      
</hibernate-mapping>


When I try to run this (either the hbm2java or the hbm2ddl target), I get an
Quote:
org.hibernate.MappingException: test\Zonentarif.hbm.xml not found

I've tried all kinds of path combinations that I can think of, but always get the same error. Any hints what I might be doing wrong are sincerely appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 5:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
first: is it intentional that you both have a configuration file (cfg.xml) AND includes a list of *.hbm.xml's ?

second: is test/Zonentarif.hbm.xml in the classpath of <hibernatetool> or the classpath <configuration> ? The error message seem to hint it is not.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 5:43 am 
Newbie

Joined: Mon Jul 11, 2005 4:27 am
Posts: 5
Hi max,

Thanks for the quick reply!

max wrote:
first: is it intentional that you both have a configuration file (cfg.xml) AND includes a list of *.hbm.xml's ?

Yes and no ;). I wasn't quite sure if both did the same or were both needed, since I've only been working on examples I found around the net. So what you are trying to tell me is that I can skip the fileset part of the configuration if my configuration is only the hibernate.cfg.xml?

max wrote:
second: is test/Zonentarif.hbm.xml in the classpath of <hibernatetool> or the classpath <configuration> ? The error message seem to hint it is not.

Do I have to specify every directory that holds mapping files in the classpath? I wasn't aware of that until now. I'll try that and see if it helps.

Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 5:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well - why would you point to a cfg.xml if it was not for using the mapping files in that file ? :)

regarding your lsat question- you just need to list the directories you would normally list in your classpath so hibernate could find that test/something.hbm.xml file in its classpath....nothing magical/weird here.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 6:06 am 
Newbie

Joined: Mon Jul 11, 2005 4:27 am
Posts: 5
Hi max,

Thanks again, I seem to be able to find the mapping file now. I had assumed that it would implicitely search the local directory, too, but it obviously didn't.

Now I get a "Could not compile the mapping document" error in Configuration. It's still the same mapping document I posted in my first post, and I've created that following whatever examples and explanations I found as well as I could. Do you see anything in there that I've missed that might upset the Hibernate tools?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 6:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what does the stacktrace say ?

if it does not show up in ant then run it with -debug or -verbose

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 7:28 am 
Newbie

Joined: Mon Jul 11, 2005 4:27 am
Posts: 5
Hi max,

I think I'm still missing something about the way the resource mapping works. The stack trace gives me a
Quote:
class test.Zonentarif not found while looking for property: id
That class doesn't exist yet because I'm trying to generate its code with hbm2java. I'm kind of lost as to the individual parts of the mapping files and what they exactly do. Is there a step-by-step explanation anywhere around?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 10:11 am 
Newbie

Joined: Mon Jul 11, 2005 4:27 am
Posts: 5
Oops, for some reason my last posting is missing about 3/4 of it's content. That'll teach me to preview each posting carefully ;-).

Anyway, I've finally figured out what my problem was. The example I was working with did have Java sources to match the mapping files, and simply skipped the property types in the mapping. I was confused because my machine kept telling me that it couldn't finde the very class that I was just trying to generate (via hbm2java). Now that I've added the property types everything works fine!

Thanks again for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 4:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes - hard for the code generator to know what type you want for a property if you dont specify it (and yes, would be nice with a more concrete error message on this)

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