-->
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: About Class generation from *.hbm.xml
PostPosted: Mon Sep 03, 2007 5:06 pm 
Newbie

Joined: Wed Mar 24, 2004 11:41 am
Posts: 3
Hi

I'm using hibernate 3.2 and a night build of hibernate tools "HibernateTools-3.2.0.200708311701-nightly"

I'm trying to make a simple example of class generation using the following mapping

<hibernate-mapping auto-import="true"
package="com.corvantis.test1.domain">

<class name="Product">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" column="name" type="String" length="40"/>
<property name="description" column="description" type="String" length="4000"/>
<property name="price" column="price" type="double" />
</class>

</hibernate-mapping>

the following ant script

<project name="test1" default="codegen" basedir=".">

<property name="lib.dir" value="lib"/>
<property name="src.dir" value="src"/>
<property name="src.hibernate" value="src"/>
<property name="source.generated" value="generated"/>

<path id="class.path">
<path location="${lib.dir}/hibernate-tools.jar"/>
<path location="${lib.dir}/hibernate3.jar"/>
<path location="${lib.dir}/freemarker.jar"/>
<path location="${lib.dir}/postgresql-8.2-506.jdbc3.jar"/>
<path location="${lib.dir}/commons-logging.jar"/>
<path location="${lib.dir}/commons-collections.jar"/>
<path location="${lib.dir}/dom4j-1.6.1.jar"/>
</path>

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

<target name="codegen">
<hibernatetool destdir="${src.dir}">
<classpath>
<path location="${lib.dir}"/>
<path location="${src.dir}"/>
</classpath>
<configuration configurationfile="hibernate.cfg.xml">
<fileset dir="${src.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2java/>
</hibernatetool>
</target>

</project>

and the following hibernate.cfg.xml

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/test1</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">postgres</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<mapping resource="test1.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Running "codegen" task I get the follwing error

INFO: Mapping class: com.corvantis.test1.domain.Product -> Product
An exception occurred while running exporter #2:hbm2java (Generates a set of .java files)
org.hibernate.InvalidMappingException: Could not parse mapping document from resource test1.hbm.xml
org.hibernate.MappingException: class com.corvantis.test1.domain.Product not found while looking for property: id
java.lang.ClassNotFoundException: com.corvantis.test1.domain.Product
A class were not found in the classpath of the Ant task.
Ensure that the classpath contains the classes needed for Hibernate and your code are in the classpath.

I don't understand why the task is looking for the Product class if this is the class that I want to generate, I'm completely sure that I'm doing something wrong any help will be preciated, two years ago I worked with hibernate and was pretty cool now I want to keep in touch again with this fabulous technology.

Best regards Rodney


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 9:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
your id does not have a type specified so hibernate tries to automatically detect it....which is done by loading the class you refer too hence the problem since it does not yet exist ;)

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