-->
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.  [ 12 posts ] 
Author Message
 Post subject: hbm2java and version 3.1
PostPosted: Fri Mar 10, 2006 7:20 am 
Newbie

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 16
I'm trying to generate Java code from an existing hbm.xml file.

I've read Chapter 4 of the reference documentation, amongst many other documents.
Unfortunately, I'm still totally cluesless as to the relationship between the hibernatetool and hbm2java Ant tasks.

My Ant file is currently as follows:

<taskdef
name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="libraries"/>

<taskdef
name="hbm2java"
classname="org.hibernate.tool.ant.Hbm2JavaExporterTask"
classpathref="libraries"/>

<target name="codegen">
<hbm2java output="${gensrc.dir}">
<fileset dir="${gensrc.dir}">
<include name="Centre.hbm.xml"/>
</fileset>
</hbm2java>
</target>

This seems to be the approach that is recommended for 2.1 but it's not clear to me just how beta 3.1 currently is.

I get the following error:

...build.xml:62: Could not create type hbm2java due to java.lang.NoSuchMethodException: org.hibernate.tool.ant.Hbm2JavaExporterTask.<init>(org.apache.tools.ant.Project)


Could someone kindly tell me where I'm going wrong please.

Many thanks
David


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 8:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
read the docs at tools.hibernate.org

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 9:14 am 
Newbie

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 16
max wrote:
read the docs at tools.hibernate.org


I was hoping for something rather more constructive than this.

I read the relevant documents I could find. In particular chapter 4 of the reference guide. A simple example of how to do something simple would be very helpful.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 5:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Did you actually try and go to tools.hibernate.org and read the docs ?

afaik we don't have any hbm2java explanation in chapter 4 of the core reference guide it is all in the *tools* doc.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 5:32 am 
Newbie

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 16
max wrote:
Did you actually try and go to tools.hibernate.org and read the docs ?

afaik we don't have any hbm2java explanation in chapter 4 of the core reference guide it is all in the *tools* doc.



Yes I have.

The Chapter 4 I'm referring to is in the Hibernate Tools Reference - Ant Tools.

It leads me to suspect that my Ant file should look something like the following:


============
<?xml version="1.0" encoding="UTF-8"?>

<project basedir="." default="compile" name="connectHub-build">

<property name="src.dir" value="${basedir}/src"/>
<property name="mappings.dir" value="${basedir}/mappings"/>
<property name="gensrc.dir" value="${basedir}/gensrc"/>
<property name="config.dir" value="${basedir}/config"/>
<property name="dest.dir" value="${basedir}/classes"/>
<property name="libs.dir" value="${basedir}/libs"/>

<path id="hibernate.tools.libraries">
<fileset dir="${libs.dir}">
<include name="hibernate-tools.jar"/>
<include name="hibernate3.jar"/>
<include name="commons-logging-1.0.4.jar"/>
<include name="dom4j-1.6.1.jar"/>
<include name="commons-collections-2.1.1.jar"/>
<include name="ojdbc14.jar"/>
<include name="velocity-1.4.jar"/>
<include name="velocity-tools-generic-1.1.jar"/>
<include name="jtidy-r8-21122004.jar"/>
</fileset>
</path>


<target name="copy-resources">
<copy todir="${dest.dir}">
<fileset dir="${mappings.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
<fileset dir="${config.dir}">
<include name="hibernate.cfg.xml"/>
</fileset>
</copy>
</target>

<taskdef
name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="hibernate.tools.libraries"/>

<taskdef
name="hbm2java"
classname="org.hibernate.tool.ant.Hbm2JavaExporterTask"
classpathref="hibernate.tools.libraries"/>

<target name="codegen" depends="copy-resources">
<hibernatetool destdir="${gensrc.dir}">
<classpath refid="project.classpath"/>
<configuration configurationfile="${config.dir}/hibernate.cfg.xml">
<fileset dir="${mappings.dir}">
<include name="Xxx.hbm.xml"/>
</fileset>
</configuration>

<!--<hbm2doc></hbm2doc>-->
<hbm2java jdk5="true" ejb3="false"/>
</hibernatetool>
</target>

</project>
============

But this fails with the bizarre error that:

class Xxx not found while looking for property: xxxSID

which in turn is caused by:

ClassNotFoundException: Xxx

which is rather odd as I have manually created Xxx.hbm.xml from which I'm trying to generate Xxx.java and then Xxx.class.

The Xxx.hbm.xml file:


===========
<?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>

<class
name="Xxx"
table="XXX">
<meta attribute="class-description">
Javadoc for the Xxx class
@author David Franklin
</meta>
<id name="xxxSID" column="SID">
<generator class="sequence">
<param name="sequence">XXX_SEQ</param>
</generator>
</id>
</class>

</hibernate-mapping>
===========

Something somewhere is going very wrong and I have spent several days going round in circles with this.
I would greatly appreciate some specific suggestions as to what the problem might be.

I am using Hibernate 3.1 and the latest Hibernate Tools beta.

David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 5:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Where in that doc do you see something that states this is needed:

Code:
<taskdef
name="hbm2java"
classname="org.hibernate.tool.ant.Hbm2JavaExporterTask"
classpathref="hibernate.tools.libraries"/>


?

In any case the error occurs because your mapping files does not contain any time information. (e.g. type="xxx" on <id>, <property> etc.)

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 5:54 am 
Newbie

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 16
max wrote:
Where in that doc do you see something that states this is needed:

Code:
<taskdef
name="hbm2java"
classname="org.hibernate.tool.ant.Hbm2JavaExporterTask"
classpathref="hibernate.tools.libraries"/>


?

In any case the error occurs because your mapping files does not contain any time information. (e.g. type="xxx" on <id>, <property> etc.)

/max


I had, perhaps incorrectly, assumed that I needed to do a taskdef for both hibernatetool and hbm2java.
If I remove the hbm2java task I then get the complaint that it can't read the mapping document but this still seems to be caused by the ClassNotFoundException I had previously.

Regarding the required contents of the Ant script, is there a working example anywhere - my sole source of information at the moment is the rather terse Chapter 4 in the Tools Reference.

Could you explain what you mean by the need for "time information" in a mapping file. I have other mapping files with no "time information" in them that work for standard CRUD operations = it's the code generation that is defeating me.

David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 6:02 am 
Hibernate Team
Hibernate Team

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

*type* information. If there is no type information how should hbm2java know which type you want it to generate ? :)

regarding examples i'll try and add one to the doc in the near future (otherwise look in the unit tests of hibernate tools)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 6:43 am 
Newbie

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 16
max wrote:
sorry a typo.

*type* information. If there is no type information how should hbm2java know which type you want it to generate ? :)

regarding examples i'll try and add one to the doc in the near future (otherwise look in the unit tests of hibernate tools)


I was basing my hbm.xml file on listing 2.2 in HIA - this doesn't specify a type and I thought I'd read that Hibernate tries to infer types where needed (not that I would expect to be able to rely on that). Having specified the type I now get my Java class generated. Hooray. But the error messages I was getting were rather unhelpful given the actual source of the problem.

An example added as part of the documentation would certainly be very helpful - and it might reduce such questions in the future!

Thanks
David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 8:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Hibernate != Hibernate Tools code generation - and what information should we use to infer the type when doing the actual code generation ?

I'll try if i can make the error message more clear.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 8:15 am 
Newbie

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 16
max wrote:
Hibernate != Hibernate Tools code generation - and what information should we use to infer the type when doing the actual code generation ?

I'll try if i can make the error message more clear.


Like I said, I wouldn't expect to rely on type interence. But its absence leads one down a very confusing path - a more informative/relevant error message would have saved a lot of pain.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 4:08 pm 
Newbie

Joined: Fri Mar 17, 2006 3:54 pm
Posts: 6
Hi,

I have to agree: while it is obvious that a "type" attribute is required once being told so, i think it would not hurt to have hbm2java spit out an error indicating that attribute is missing. I wasted some time finding this out as well.

Nicolas


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