-->
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: hbm2java can't find HBM files
PostPosted: Wed Sep 07, 2005 5:39 pm 
Newbie

Joined: Wed Sep 07, 2005 5:08 pm
Posts: 1
Hi. I'm evaluating Hibernate for a project. The project uses UML to define the database, and I can easily translate this into a HBM file. So I will need to use hbm2java to generate the POJO objects.

I started with the intro tutorial from the roadmap page and got the "event" object to store and list itself. I was happy.

I then figured I would set up ant to generate the Event.java code from the Event.hbm.xml as a feasability test.

I'm using hibernate 3.0.5. I grabbed the 3.0.0.alpha4a tools distribution.

Using the forums, I determined I needed to unzip one of the jars in the tools distribution to get at the hibernate-tools stuff I needed for ANT. Hopefully I did this right. At any rate I stopped getting compile errors after I did this, which was nice.

So I have this in my build.xml, which I basically made by following the tutorial, then tweaking it based on the forums and docs:

<project name="java01" basedir="." default="compile">

<path id="hibernate.classpath">
<fileset dir="${basedir}/antlib2">
<include name="**/hibernate-tools.jar"/>
<include name="**/velocity-1.4.jar"/>
<include name="**/velocity-tools-generic-1.1.jar"/>
<include name="**/jtidy-r8-21122004.jar"/>
<include name="**/hibernate3.jar"/>
<include name="**/ehcache-1.1.jar"/>
<include name="**/commons-collections-2.1.1.jar"/>
</fileset>
<fileset dir="${basedir}/lib">
<include name="**/commons-logging-1.0.4.jar"/>
<include name="**/dom4j-1.6.jar"/>
<include name="**/postgresql-8.0-312.jdbc3.jar"/>
</fileset>
</path>

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

<property name="sourcedir" value="${basedir}/src"/>
<property name="targetdir" value="${basedir}/bin"/>
<property name="librarydir" value="${basedir}/lib"/>

<path id="libraries">
<fileset dir="${librarydir}">
<include name="*.jar"/>
</fileset>
</path>

<target name="compile" depends="clean, copy-resources">
<javac srcdir="${sourcedir}"
destdir="${targetdir}"
classpathref="libraries"/>
</target>

<target name="copy-resources">
<copy todir="${targetdir}">
<fileset dir="${sourcedir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>

<target name="run" depends="compile">
<java fork="true" classname="EventManager" classpathref="libraries">
<classpath path="${targetdir}"/>
<arg value="${action}"/>
</java>
</target>

<target name="hbm2java" description="Generate .java from .hbm files." >
<hibernatetool destdir="${basedir}/gen">
<configuration configurationfile="hibernate.cfg.xml"/>
<hbm2java/>
</hibernatetool>
</target>

<target name="hbm2ddl" description="Generate .java from .hbm files." >
<hibernatetool destdir="${basedir}/gen">
<configuration configurationfile="src/hibernate.cfg.xml"/>
<hbm2ddl/>
</hibernatetool>
</target>

</project>

My .cfg.xml file 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>

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

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

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

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

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

</session-factory>

</hibernate-configuration>

Yes, I'm using postgres instead of HSQL. It seems to work fine.

In my src directory, I have the event.hbm.xml file from the tutorial:

<?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="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>

</hibernate-mapping>

OK, so my problem is this: if I run "ant hbm2java" or "ant hbm2ddl" it tells me it can't find Event.hbm.xml:

C:\devel\dizave\hib1>ant hbm2java
Buildfile: build.xml

hbm2java:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2java (Generates a set of .java files)
[hibernatetool] Sep 7, 2005 5:34:46 PM org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: Hibernate 3.0.5
[hibernatetool] Sep 7, 2005 5:34:46 PM org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: hibernate.properties not found
[hibernatetool] Sep 7, 2005 5:34:46 PM org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: using CGLIB reflection optimizer
[hibernatetool] Sep 7, 2005 5:34:46 PM org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: using JDK 1.4 java.sql.Timestamp handling
[hibernatetool] Sep 7, 2005 5:34:47 PM org.hibernate.cfg.Configuration configure

[hibernatetool] INFO: configuring from file: hibernate.cfg.xml

BUILD FAILED
C:\devel\dizave\hib1\build.xml:78: org.hibernate.HibernateException: could not find file: C:\devel\dizave\hib1\hibernate.cfg.xml

Total time: 1 second


I've tried about every variation of path I can think of in the hibernate.cfg.xml to point to the Event.hbm.xml. I'm not sure what else to do. The layout of the plugin source hasn't been intuitive to me so far so I haven't found the bit of source code responsible for this yet.

I'm going to dive into that next, but I figured it would be worthwhile to concurrently throw this out there.

If there is any way I can be helpful in documenting this, I'd be glad to.

Incidentally, is the hbm2java.bat a Hibernate2 only feature? The book I bought says I should use that but I haven't found it so far.

Thanks for any help,

David


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 6:55 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Try adding your bin directory to your hibernate.classpath. Your hbm.xml is looked up as a resource, so it needs to be found on the classpath.


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.