-->
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.  [ 4 posts ] 
Author Message
 Post subject: Basic hbm2java example w/ tools 3.1??
PostPosted: Wed Jun 07, 2006 2:57 pm 
Newbie

Joined: Wed Jun 07, 2006 1:10 pm
Posts: 2
Does anyone have a complete, working example of using hbm2java with tools 3.1 that you can point me to? I've looked at all the documentation I can find, but I consistently get the same errors, even with my most basic attempts.

I see the following using hbm2java from Ant as well as the Eclipse plugin:

Code:
Buildfile: build.xml

pojo:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2java (Generates a set of .java files)
[hibernatetool] An exception occurred while running exporter #2:hbm2java (Generates a set of .java files)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.MappingException: Could not read mappings from resource: Book.hbm.xml
[hibernatetool] org.hibernate.MappingException: class Book not found while looking for property: isbn
[hibernatetool] java.lang.ClassNotFoundException: Book

BUILD FAILED
C:\devl\encoderGrouper\psi\hibernateTest\JavaSource\build.xml:34: org.hibernate.MappingException: Could not read mappings from resource: Book.hbm.xml



My files could not be much simpler...

build.xml:

Code:
<?xml version="1.0"?>

<project default="pojo" basedir=".">

  <property name="src.dir"          value="."/>
  <property name="build.dir"        value="."/>
  <property name="jlib.dir"         value="c:/devl/j-lib"/>
  <property name="hbm.dir"          value="${jlib.dir}/hibernate-3.1"/>
  <property name="hbmtools.dir"     value="c:/tools/eclipse/plugins/org.hibernate.eclipse_3.1.0.beta5/lib/tools"/>

  <path id="toolslib">
    <path location="."/>
    <path location="${src.dir}" />
    <path location="${build.dir}" />
    <path location="${hbmtools.dir}/hibernate-tools.jar" />
    <path location="${hbm.dir}/hibernate3.jar" />
    <path location="${hbmtools.dir}/freemarker.jar" />
    <path location="${hbmtools.dir}/jtidy-r8-21122004.jar" />
    <path location="${jlib.dir}/postgresql-8.1-405.jdbc3.jar" />
    <path location="${hbm.dir}/lib/dom4j-1.6.1.jar"/>
    <path location="${hbm.dir}/lib/log4j-1.2.11.jar"/>
    <path location="${hbm.dir}/lib/commons-logging-1.0.4.jar"/>
    <path location="${hbm.dir}/lib/commons-collections-2.1.1.jar"/>
    <path location="${hbm.dir}/lib/cglib-2.1.3.jar"/>
    <path location="${hbm.dir}/lib/ehcache-1.1.jar"/>
    <path location="${hbm.dir}/lib/jta.jar"/>
  </path>

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

  <target name="pojo" description="generate java pojo classes with hbm2java">
    <hibernatetool destdir="${build.dir}">
      <configuration configurationfile="${src.dir}/hibernate.cfg.xml">
   <fileset dir="${src.dir}">
     <include name="**/*.hbm.xml"/>
   </fileset>
      </configuration>
      <hbm2java/>
    </hibernatetool>
  </target>

</project>


hibernate.cfg.xml:

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

<hibernate-configuration>

  <session-factory >

    <!-- Database connection settings -->
    <property name="connection.driver_class">org.postgresql.Driver</property>
    <property name="connection.url">jdbc:postgresql://localhost:5432/test</property>
    <property name="connection.username">postgres</property>
    <property name="connection.password"></property>

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

    <mapping resource="Book.hbm.xml"/>

  </session-factory>

</hibernate-configuration>


Book.hbm.xml:

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>

    <class name="Book" table="BOOK">
        <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_ISBN" name="isbn">
        </property>
    </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 3:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the error says:

"class Book not found while looking for property: isbn"

meaning property isbn did not have any type information thus the tools tries to load the class to figure it out.

If you don't yet have the classes it will obviously fail.

Set the type of the propery and be happy ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: thanks
PostPosted: Thu Jun 08, 2006 8:56 am 
Newbie

Joined: Wed Jun 07, 2006 1:10 pm
Posts: 2
Bad example from onjava.com... thanks for the help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 9:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what "bad example from onjava" ? do you have a link.?

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