Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hello
I am new to this hibernate tools and ant scripts.
I want to generate a simple POJO Using hbm file.I think i was wrong in deciding the correct jar files for this application.Please any one can help to over come this problem.Can any one please find the where i went wrong and what i have to do.It will be a great help if any one can send source code or link for me to
illaanil@rediffmail.com
Hibernate version: 3
This is my ant script:
<project default="codegen1" basedir=".">
<property name="src" value="src"/>
<property name="sql" value="sql" />
<property name="hibernate3jars" value="lib/hibernate-3.1.2"/>
<property name="hibernatetools3" value="/lib/hibernate-tools-3.1B4/plugins/org.hibernate.eclipse_3.1.0.beta4/lib/tools"/>
<property name="hsqldbs" value="lib/hsqldb-1.8.0.2/lib"/>
<path id="classpath.base">
<pathelement location="${src}"/>
<pathelement location="${hibernate3jars}/hibernate3.jar"/>
<fileset dir="${hibernate3jars}/lib" includes="**/*.jar"/>
<pathelement location="${hsqldbs}/lib/hsqldb.jar"/>
</path>
<path id="classpath.tools">
<path refid="classpath.base"/>
<pathelement location="${hibernatetools3}/hibernate-tools.jar"/>
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath.tools"/>
<target name="codegen1">
<hibernatetool destdir="${sql}">
<configuration configurationfile="${src}/hibernate.cfg.xml">
<fileset dir="${src}">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2java />
</hibernatetool>
</target>
</project>
This is the error :
Full stack trace of any exception that occurs:
ader
[hibernatetool] Jun 27, 2008 2:52:52 AM org.apache.velocity.tools.generic.log.CommonsLogLogSystem logVelocityMessage
[hibernatetool] INFO: ResourceManager : found pojo/PojoToString.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
[hibernatetool] Jun 27, 2008 2:52:52 AM org.apache.velocity.tools.generic.log.CommonsLogLogSystem logVelocityMessage
[hibernatetool] INFO: ResourceManager : found pojo/PojoEqualsHashcode.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
[hibernatetool] Jun 27, 2008 2:52:52 AM org.apache.velocity.tools.generic.log.CommonsLogLogSystem logVelocityMessage
[hibernatetool] SEVERE: Method needsEqualsHashCode threw exception for reference $pojo in template pojo/PojoEqualsHashcode.vm at [1,5]
[hibernatetool] Jun 27, 2008 2:52:52 AM org.apache.velocity.tools.generic.log.CommonsLogLogSystem logVelocityMessage
[hibernatetool] SEVERE: Method get threw exception for reference $templates in template pojo/Pojo.vm at [17,1]
BUILD FAILED
C:\Ant\bin\hibernate\build.xml:28: org.hibernate.tool.hbm2x.ExporterException: MethodInvocationException while processing template Pojo. Invocation of meth
od 'get' in class org.hibernate.tool.hbm2x.TemplateHelper$Templates threw exception class org.hibernate.tool.hbm2x.ExporterException : MethodInvocationExc
eption while processing template pojo/PojoEqualsHashcode.vm. Invocation of method 'needsEqualsHashCode' in class org.hibernate.tool.hbm2x.pojo.EntityPOJOC
lass threw exception class java.lang.NoSuchMethodError : org.hibernate.mapping.Property.isNaturalIdentifier()Z
Total time: 1 second
This are my cfg file :
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:hsqldb:file:testdb;shutdown=true</property>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">0</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- You will usually want to set this to true while debugging Hibernate queries -->
<property name="hibernate.show_sql">true</property>
<!--
<mapping resource="sample/entity/lazy/User.hbm.xml"/>
<mapping resource="sample/entity/lazy/Email.hbm.xml"/>
-->
</session-factory>
</hibernate-configuration>
This is my mapping file :
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="sample.entity.lazy.Email" table="lazy_email">
<id access="field" name="id" type="int" column="id">
<generator class="native"/>
</id>
<property access="field" name="email" column="name" type="string" unique="true"/>
</class>
</hibernate-mapping>
Read this:
http://hibernate.org/42.html