Hi
I'm trying to teach myself Hibernate and have been following a couple of online tutorials. However, I am getting an error which I can't fix....can anybody shed any light ?!?
I have the following hibernate.cfg.xml file....
Code:
<?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">com.mysql.jdbc.Driver</property>
<property name="connection.url">dbc:hsqldb:hsql://localhost</property>
<property name="connection.username"></property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</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="uk/co/yahoo/wjday/bean/MatchBean.hbm.xml"/>
<mapping resource="uk/co/yahoo/wjday/bean/NationalityBean.hbm.xml"/>
<mapping resource="uk/co/yahoo/wjday/bean/PlayerBean.hbm.xml"/>
<mapping resource="uk/co/yahoo/wjday/bean/PlayerMatchBean.hbm.xml"/>
<mapping resource="uk/co/yahoo/wjday/bean/ClubBean.hbm.xml"/>
<mapping resource="uk/co/yahoo/wjday/bean/CompetitionBean.hbm.xml"/>
<mapping resource="uk/co/yahoo/wjday/bean/LoginBean.hbm.xml"/>
</session-factory>
</hibernate-configuration>
and the following MatchBean.hbm.xml file.....
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="uk.co.yahoo.wjday.bean.MatchBean" table="MATCH">
<id name="id" type="long" column="MATCH_ID">
<generator class="native"/>
</id>
<property name="date" type="date" not-null="true"/>
<property name="venue" type="string" not-null="true"/>
<property name="goalsFor" type="integer" not-null="true"/>
<property name="goalsAgainst" type="integer" not-null="true"/>
<property name="matchReport" type="text" not-null="false"/>
<property name="homeKit" type="blob" not-null="false"/>
<property name="awayKit" type="blob" not-null="false"/>
<many-to-one name="opposition"column="opposition_id"
class="ClubBean"/>
<many-to-one name="competition"column="competition_id"
class="CompetitionBean"/>
</class>
</hibernate-mapping>
I am trying to get Hibernate to create the Java classes for me from these mapping files using the following build script....
Code:
<?xml version="1.0"?>
<project name="maggies" default="dist" basedir=".">
<!-- Tomcat home directory, the path to where your tomcat is installed -->
<property name="projname" value="mags"/>
<property name="tomcathome" value="c:/tomcat/apache-tomcat-5.5.16"/>
<property name="root" value="c:/development/mags" />
<property name="src" value="${root}/src" />
<property name="classes" value="${root}/classes" />
<property name="lib" value="${root}/lib" />
<property name="jar" value="${root}/jar" />
<property name="deploy" value="${tomcathome}/webapps/${projname}/WEB-INF" />
<property name="deployClasses" value="${deploy}/classes" />
<property name="deployLib" value="${deploy}/lib" />
<property name="generateLib" value="C:/hibernateTools/plugins/org.hibernate.eclipse_3.2.0.beta8/lib" />
<property name="generateAnnotations" value="${generateLib}/annotations" />
<property name="generateHibernate" value="${generateLib}/hibernate" />
<property name="generateTools" value="${generateLib}/tools" />
<property name="velocity" value="C:/hibernateVelocity/jar" />
<!-- ***************************************** CLEAN ***************************************** -->
<target name="clean">
<delete dir="${classes}" />
<echo message="Classes deleted"/>
<delete dir="${tomcathome}/webapps/${projname}" />
<echo message="Web application deleted"/>
</target>
<!-- ***************************************** GENERATE CODE ************************************ -->
<path id="classpath">
<fileset dir="${generateAnnotations}">
<include name="*.jar" />
</fileset>
<fileset dir="${generateHibernate}">
<include name="*.jar" />
</fileset>
<fileset dir="${generateTools}">
<include name="*.jar" />
</fileset>
<fileset dir="${velocity}">
<include name="*.jar" />
</fileset>
</path>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="classpath" />
<target name="codegen">
<hibernatetool destdir="${src}/output">
<configuration configurationfile="${src}/hibernate.cfg.xml">
</configuration>
<hbm2java/>
</hibernatetool>
</target>
<!-- ***************************************** COMPILE ***************************************** -->
<target name="compile">
<mkdir dir="${classes}"/>
<javac destdir="${classes}">
<src path="${src}" />
<classpath>
<fileset dir="${lib}">
<include name="**/*.jar" />
<include name="**/*.zip" />
</fileset>
</classpath>
</javac>
<echo message="Compilation of code completed"/>
</target>
<!-- ***************************************** DEPLOY ***************************************** -->
<target name="dist" depends="compile" >
<copy todir="${deploy}">
<fileset dir="${src}/WEB-INF"/>
</copy>
<copy todir="${deployClasses}">
<fileset dir="${classes}"/>
</copy>
<copy todir="${deployLib}">
<fileset dir="${lib}"/>
</copy>
<copy todir="${deploy}">
<fileset dir="${classes}">
<include name="**/*.jsp" />
<include name="**/*.html" />
</fileset>
</copy>
<echo message="Application deployed"/>
</target>
</project>
However, when I invoke the 'codegen' target, I get the following error...
Code:
C:\development\mags>ant codegen
Buildfile: build.xml
codegen:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2java (Generates a set of .java files)
[hibernatetool] log4j:WARN No appenders could be found for logger (org.hibernate
.cfg.Environment).
[hibernatetool] log4j:WARN Please initialize the log4j system properly.
[hibernatetool] An exception occurred while running exporter #2:hbm2java (Genera
tes a set of .java files)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.MappingNotFoundException: resource: uk/co/yahoo/wj
day/bean/MatchBean.hbm.xml not found
[hibernatetool] A resource located at uk/co/yahoo/wjday/bean/MatchBean.hbm.xml w
as not found.
[hibernatetool] Check the following:
[hibernatetool]
[hibernatetool] 1) Is the spelling/casing correct ?
[hibernatetool] 2) Is uk/co/yahoo/wjday/bean/MatchBean.hbm.xml available vi
a the classpath ?
[hibernatetool] 3) Does it actually exist ?
BUILD FAILED
C:\development\mags\build.xml:57: org.hibernate.MappingNotFoundException: resour
ce: uk/co/yahoo/wjday/bean/MatchBean.hbm.xml not found
Total time: 5 seconds
C:\development\mags>
The files definately exist and the casing is correct. Do the *.hbm.xml files have to be on the classpath? The *.hbm.xml and hiberanate.cfg.xml are all under the same project root (I have hibernate.cfg.xml under WEB-INF and the individual *.hbm.xml files in a src sub-directory).
I know that the hibernate.cfg.xml is being found, since if I swap the order of the *.hbm.xml files, the exception complains about a different mapping files not being found (i.e. the first one in the file).
Can anybody spot anything obviously wrong with the above? Your help is greatly appreciated !
Bill