-->
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.  [ 8 posts ] 
Author Message
 Post subject: Problem using Ant tasks for Hibernate Tools 3.0
PostPosted: Wed Jun 15, 2005 2:24 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 2:00 pm
Posts: 38
Hi,

I'm trying to set-up some Ant scripts to run the Hibernate Tools in Eclipse 3.0.2. This should be alright, since the Ant tools are independent of Eclipse platform right?

Here's my hibernate.cfg.xml file:

Code:
<hibernate-configuration>
   <session-factory>
      <!--
         Database connection details: use either JNDI datasource or local driver
         1. Using JNDI datasource: set the JNDI reference
         <property name="connection.datasource">java:comp/env/jdbc/DEV</property>
         2. Local connection
      //-->
      <property name="connection.datasource">t3://127.0.0.1:7001/jdbc/DEV</property>
      <!--
         dialects
         SQL Server: net.sf.hibernate.dialect.SQLServerDialect
         Oracle 9/10g: net.sf.hibernate.dialect.Oracle9Dialect
         MySQL: net.sf.hibernate.dialect.MySQLDialect
      //-->
      <property name="dialect">
         org.hibernate.dialect.SQLServerDialect
      </property>
      <!--
         Transaction parameters
         hibernate.transaction.factory_class: either "org.hibernate.transaction.JTATransactionFactory"
         or "org.hibernate.transaction.JDBCTransactionFactory"
         hibernate.transaction.manager_lookup_class: "org.hibernate.transaction.WeblogicTransactionManagerLookup"
         for Weblogic
         jta.UserTransaction: The JNDI name for the JTA User Transaction
         Example:
         <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
         <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
         <property name="jta.UserTransaction">t3://127.0.0.1:7001/javax/transaction/UserTransaction</property>
      //-->
      <property name="hibernate.transaction.factory_class">
         net.sf.hibernate.transaction.JDBCTransactionFactory
      </property>
      <!--
         Other parameters
         hibernate.connection.isolation: 0=NONE, 1=READ_UNCOMMITTED, 2=READ_COMMITTED, 4=REPEATABLE_READS, 8=SERIALIZABLE
      //-->
      <property name="hibernate.show_sql">true</property>
      <property name="hibernate.max_fetch_depth">1</property>
      <property name="hibernate.jdbc.fetch_size">10</property>
      <property name="hibernate.jdbc.batch_size">20</property>
      <property name="hibernate.jdbc.use_streams_for_binary">true</property>
      <property name="hibernate.jdbc.batch_size">20</property>
      <property name="hibernate.connection.isolation">2</property>
      <!-- Mappings file references for your Java objects -->
      <mapping resource="project/vo/User.hbm.xml" />


Here's my Ant script:

Code:
<project name="Hibernate Tools"  default="init"  basedir=".">

<taskdef name="hibernatetool"
   classname="org.hibernate.tool.ant.HibernateToolTask"
   classpath="../supportJARs/hibernateTools/hibernate-tools.jar;
            ../supportJARs/hibernateTools/velocity-1.4.jar;
            ../supportJARs/hibernateTools/velocity-tools-generic-1.1.jar;
            ../supportJARs/hibernateTools/jtidy-r8-21122004.jar;
            ../supportJARs/hibernateTools/hibernate3.jar;
            ../supportJARs/jdts-1.0.jar;
            ../supportJARs/lib/commons-logging-1.0.4.jar;
            ../supportJARs/lib/dom4j-1.4.jar;
            ../supportJARs/lib/commons-collections-2.1.1.jar"
/>

<target name="init">
</target>

<target name="generateJava" depends="init">
<hibernatetool destdir="..src">
<configuration configurationfile="..src/hibernate.cfg.xml"  />
<hbm2java/> 
</hibernatetool>


The Ant script is in a folder called "deploy", which is at the same level as the folder "src", where the source files and the Hibernate XMLs are.

When I tried to run the script, I got this complaint from Ant:

BUILD FAILED: F:\Eclipse Project (New)\Hibernate\deploy\build_HibernateTools.xml
:20: org.hibernate.MappingException: Resource: project/vo/User.hbm.xml not found


Seems like a pathing issue. Any ideas how I can configure this up properly?

Thanks in advance for any advice!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 3:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
<mapping resource="project/vo/User.hbm.xml" />

uses the classpath to load stuff. So you need to have that in a classpath just like if you used normal hibernate.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 4:24 pm 
Newbie

Joined: Wed Mar 30, 2005 6:50 pm
Posts: 8
I'm having a similar problem and am trying to include the hbm.xml files in my class path but it does not appear to be working. Are you saying to add it to the classpath of the taskdef?

I have:

<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="[b]lib.class.path[/b]"/>

<hibernatetool destdir="${gen.dir}">
<configuration configurationfile="${conf.dir}/hibernate.cfg.xml" >
<fileset dir="${persist.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2java/>
</hibernatetool>

and the lib.class.path reference is:

<path id="lib.class.path">
<pathelement path="${name2}.jar"/>
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${persist.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</path>

I'm getting the same problem


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 4:25 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 2:00 pm
Posts: 38
Just to confirm: so that means I should add "../src/project/vo/User.hbm.xml" to classpath?

Ouch, that could prove inconvenient, since that means I'll need to change the classpath each time I change my mappings in hibernate.cfg.xml, unless classpath allows something like "..src/project/vo/*.User.hbm.xml", which I doubt?

Or maybe a nested <fileset> element in classpath??

I think I'll just add the required properties to the properties file for my build script, and then use the <fileset> method to specify the files needed via filters (which is the method presented in the documentation for this generator). That way, I won't need to hard-code any mapping file entries.

Thanks for your tip, though. Might come in handy some time down the line :-)

max wrote:
<mapping resource="project/vo/User.hbm.xml" />

uses the classpath to load stuff. So you need to have that in a classpath just like if you used normal hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 5:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no - you just need to add what is your normal classpath. so it should be the root directory of that path.

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 10:51 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 2:00 pm
Posts: 38
Hi Max,

Sorry, too many "paths" here to take. Confused? :-)

What do you mean by "normal classpath" and "root directory of that path"?

By normal classpath, do you mean the Java build path for the project?And root directory of that path refers to the root "src" folder (or structure where the *hbm.xml can be found?


max wrote:
no - you just need to add what is your normal classpath. so it should be the root directory of that path.

-max


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 2:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes.

It seems people cant grasp that the configuration of the tools is *exactly* the same as if they use hibernate.

If you run hibernate with something like a resource reference to "project/vo/User.hbm.xml" then it only works if you have the root directory of this file in your classpath. e.g. if project/vo/User.hbm.xml is located at /happy/happy/shiny/build/classes/people/project/vo/User.hbm.xml then you would need to have /happy/happy/shiny/build/classes/ in your classpath. (more often than not you also have the files in a .jar then it is the jar that is the "root" and should be put in the classpath)

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 2:57 am 
Beginner
Beginner

Joined: Wed Jun 15, 2005 2:00 pm
Posts: 38
Ok. Finally got it working :-)

Got a bit confused about what "project classpath" meant. You were refering to the classpath for the Ant project, whereas I thought you meant the classpath for the Eclipse project. That was why it didn't work the first time round...

Glad that this is sorted out now...

Have learnt quite a bit about Hibernate from the documentation and through the forums. Good stuff here! It exactly addresses some of the persistence issues that developers face when it comes to handling the database tier.

Great work guys!!

max wrote:
yes.

It seems people cant grasp that the configuration of the tools is *exactly* the same as if they use hibernate.

If you run hibernate with something like a resource reference to "project/vo/User.hbm.xml" then it only works if you have the root directory of this file in your classpath. e.g. if project/vo/User.hbm.xml is located at /happy/happy/shiny/build/classes/people/project/vo/User.hbm.xml then you would need to have /happy/happy/shiny/build/classes/ in your classpath. (more often than not you also have the files in a .jar then it is the jar that is the "root" and should be put in the classpath)

-max


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.