-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with Java Code generation using from hbm.xml
PostPosted: Sun Jan 29, 2006 10:17 pm 
Newbie

Joined: Sun Jan 29, 2006 7:45 pm
Posts: 5
I am using 3.1.2 hibernate and tools 3.1 beta 4 (tried beta2 also).

I am new to Hibernate and I spent quite a while searching around for a while at google and here. I am stuck with a simple problem.

I have a "Book.hbm.xml" and I want to generate "Book.java" using "hibernatetool".

I have ant tasks defined and i got past all the "classpath" issues. Now the hibernate tries to instantiate "Book", which is the class I am trying to generate. Somehow I am not telling it to generate. I am suspecting that I am not specifying something in the cfg.xml. I dont know what.

The Book.hbm.xml is

<?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="Book" table="BOOK">
<meta attribute="class-description">
A Book business object.
@author Duke
</meta>
<id name="id" type="string" unsaved-value="null" >
<column name="BOOK_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property column="BOOK_NAME" name="name"/>
<property column="BOOK_ISBN" name="isbn">
<meta attribute="field-description">
The unique ISBN code for this book.
</meta>
</property>
</class>

</hibernate-mapping>


The hibernate.cfg.xml is

<?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 name="AutoSchoolHibernate">
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://server=localhost;port=1433;DatabaseName=interlacemain;SelectMethod=cursor</property>
<property name="hibernate.connection.username">interlace</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>

</session-factory>
</hibernate-configuration>



The ant file:


<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask">
<classpath>
<fileset
dir="${eclipse.root}/plugins/org.hibernate.eclipse_3.1.0.beta4/lib/tools">
<include name="hibernate-tools.jar"/>
<include name="velocity-1.4.jar"/>
<include name="velocity-tools-generic-1.4.jar"/>
<include name="jtidy-r8-21122004.jar"/>
</fileset>
<fileset dir="${interlace.install.root}/lib">
<include name="hibernate.jar"/>
<include name="msbase.jar"/>
<include name="mssqlserver.jar"/>
<include name="msutil.jar"/>
<include name="asm-attrs.jar"/>
<include name="asm.jar"/>
<include name="c3p0-0.9.0.jar"/>
<include name="cglib-2.1.3.jar"/>
<include name="concurrent-1.3.2.jar"/>
<include name="connector.jar"/>
<include name="dom4j-1.6.1.jar"/>
<include name="ehcache-1.1.jar"/>
<include name="jaas.jar"/>
<include name="jacc-1_0-fr.jar"/>
<include name="jaxen-1.1-beta-7.jar"/>
<include name="jboss-common.jar"/>
<include name="jboss-jmx.jar"/>
<include name="jboss-system.jar"/>
<include name="jgroups-2.2.8.jar"/>
<include name="jta.jar"/>
<include name="oscache-2.1.jar"/>
<include name="proxool-0.8.3.jar"/>
<include name="swarmcache-1.0rc2.jar"/>
<include name="syndiag2.jar"/>
<include name="xml-apis.jar"/>
<include name="commons-collections.jar"/>
</fileset>
<path location="${interlace.product.root}"/>
</classpath>
</taskdef>
<mkdir dir="${src.generated.dir}"/>
<mkdir dir="${src.generated.dir}/@{packagedir}"/>
<hibernatetool destdir="@{target}">
<configuration configurationfile="@{configFile}">
<fileset dir="hibernate">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2java/>
</hibernatetool>
=============
The error msg I am getting is:

Caused by: org.hibernate.MappingException: Could not read mapping document from file: C:\work\programs\autoschool\base\main\hibernate\basic\Book.hbm.xml
at org.hibernate.cfg.Configuration.addFile(Configuration.java:270)
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.java:140)
... 37 more
Caused by: org.hibernate.MappingException: class Book not found while looking for property: name
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:80)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2138)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2115)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2005)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:368)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.hibernate.cfg.Configuration.addFile(Configuration.java:267)
... 38 more
Caused by: java.lang.ClassNotFoundException: Book
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1166)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1107)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:977)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:76)
... 48 more
--- Nested Exception ---

Thanks
Kumar


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 1:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
pretty hard for the hbm2java code generation to know which type you want for the name when you don't specify one, correct ? :)

try <property name="name" type="string" ... /> and you will see that hibernate does not try to use reflection to get the type.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 2:06 am 
Newbie

Joined: Sun Jan 29, 2006 7:45 pm
Posts: 5
Thanks a lot. That worked.


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