I am just starting with Hibernate Tools and I will really appreciate some help.
I am trying to generate POJOs and DAO code from my hbm files using ant.
Under my project directory I have
ProjectDir
|
+/src - it is empty now
+/etc
| |-Hibernate.cfg.xml
| |-Account.hbm.xml
| |-User.hbm.xml
| |-Address.hbm.xml
| |-Invoice.hbm.xml
|
|-build.xml
I am trying to follow documentation and I have in my cfg.xml
Code:
<mapping resource="etc/Account.hbm.xml"/>
<mapping resource="etc/Address.hbm.xml"/>
<mapping resource="etc/User.hbm.xml"/>
<mapping resource="etc/Invoice.hbm.xml"/>
My ant target is defined
Code:
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib"/>
<target name="-pre-compile" depends="pojo-gen,dao-gen"/>
<target name="pojo-gen">
<hibernatetool destdir="${src.dir}">
<configuration configurationfile="etc/Hibernate.cfg.xml"/>
<hbm2java jdk5="true" ejb3="false"/>
</hibernatetool>
</target>
<target name="dao-gen">
<hibernatetool destdir="${src.dir}">
<configuration configurationfile="etc/Hibernate.cfg.xml"/>
<hbm2dao jdk5="true" ejb3="false"/>
</hibernatetool>
</target>
When I am running ant, I am getting
Quote:
pojo-gen:
Executing Hibernate Tool with a Standard Configuration
1. task: hbm2java (Generates a set of .java files)
An exception occurred while running exporter #2:hbm2java (Generates a set of .java files)
To get the full stack trace run ant with -verbose
org.hibernate.MappingNotFoundException: resource: etc/Account.hbm.xml not found
A resource located at etc/Account.hbm.xml was not found.
Check the following:
1) Is the spelling/casing correct ?
2) Is etc/Account.hbm.xml available via the classpath ?
3) Does it actually exist ?
org.hibernate.MappingNotFoundException: resource: etc/Account.hbm.xml not found
...
It should be something very simple but I do not see it.
I tried to replace resource with the file, take out etc/, hibernate still cannot find the file.
I then decided to go without cfg.xml and changed my ant target to
Code:
<target name="pojo-gen">
<hibernatetool destdir="${src.dir}">
<configuration>
<fileset dir="${src.etc.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2java jdk5="true" ejb3="false"/>
</hibernatetool>
</target>
It is now reading the file but throws another exception:
Quote:
An exception occurred while running exporter #2:hbm2java (Generates a set of .java files)
To get the full stack trace run ant with -verbose
Failed in building configuration when adding C:\SDF\CodeBase\HBM\etc\Account.hbm.xml
org.hibernate.InvalidMappingException: Could not parse mapping document from file C:\SDF\CodeBase\HBM\etc\Account.hbm.xml
org.hibernate.MappingException: class Account not found while looking for property: accountId
java.lang.ClassNotFoundException: Account
A class were not found in the classpath of the Ant task.
Ensure that the classpath contains the classes needed for Hibernate and your code are in the classpath.
...
It is suppose to generate Account class or I am missing something?
Please give me a tip.
Thanks.