-->
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: trouble understanding how to use hbm2java properly
PostPosted: Sun Jun 03, 2007 11:13 pm 
Newbie

Joined: Mon Oct 17, 2005 3:26 pm
Posts: 4
Hibernate version:
hibernate-3.2

Hibernate Tools version:
HibernateTools-3.2.0.beta9a.zip

I'm trying to use the Hibernate Tools hbm2java task to create my POJOs. Basically I'd like to create hbm.xml files and define my domain objects via xml. Then I'd like to run hbm2java to generate my POJOs for me. Is this the right tool?

If so, I don't quite understand the configuration and setup that I'm supposed to be using. I have the hibernate tool configured to point to my hibernate.cfg.xml file in ./src. I also have a Person.hbm.xml file in ./src/org/enology/model/dao/Person.hbm.xml.

If I run the hbm2xml task and DO NOT have my Person.hbm.xml file mapped in it, it does not create a POJO for it.

If I do map it in hibermat.cfg.xml and I do not yet have a Person.java created, then it complains that it cannot find class Person while looking for the property id.

I then have to create a Person class with all the properties in it, otherwise I get an exception on any property that does not exist in it.

It seems I've gotten myself into a bit of a chicken and egg situation here. Clearly it makes not sense to use the tool to generate POJOs for you, if you have create them before hand.

Please find my build.xml below, and let me know if there's something I'm doing wrong:




Code:
<?xml version="1.0" encoding="UTF-8"?>
<project name="vinotrails" default="dist" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>
  <property name="jdbc.driver.jar" location="../deps/hsqldb/lib/hsqldb.jar"/>
 
  <path id="toolslib">
    <path location="lib/hibernate-tools.jar" />
    <path location="../deps/hibernate-3.2/hibernate3.jar" />
    <path location="lib/freemarker.jar" />
    <path location="${jdbc.driver.jar}" />
    <path location="../deps/hibernate-3.2/lib/log4j-1.2.11.jar"/>
    <path location="../deps/hibernate-3.2/lib/commons-logging-1.0.4.jar"/>
    <path location="../deps/hibernate-3.2/lib/commons-collections-2.1.1.jar"/>
    <path location="../deps/hibernate-3.2/lib/dom4j-1.6.1.jar"/>
    <path location="${src}"/>
    <path location="${build}"/>
  </path>
   
  <taskdef name="hibernatetool"
         classname="org.hibernate.tool.ant.HibernateToolTask"
         classpathref="toolslib" />

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}"/>
    <hibernatetool destdir="${src}">
      <configuration configurationfile="${src}/hibernate.cfg.xml"/>
      <hbm2java/>
    </hibernatetool>
  </target>

  <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/lib/vinotrails-${DSTAMP}.jar" basedir="${build}"/>
  </target>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
</project>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 3:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you don't specify a type for your properties/id's then hbm2java will fail.

types need to be specified how else should hbm2java know the correct type ?

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