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>