I try to get my db schema exported but I get:
Quote:
BUILD FAILED: /home/tezem/workspace/ExamProj/src/build.xml:49: Schema text failed: net.sf.hibernate.MappingException: persistent class [core.Answer] not found
Everything I tried was not working.
Here you get my build.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Project" basedir="." default="about">
<target name="clean" depends="init" description="removes all directories related to this build">
<delete dir="${dist}"/>
</target>
<target name="init" description="Initializes properties that are used by other targets.">
<property name="dist" value="../dist"/>
</target>
<target name="prepare" depends="init,clean" description="creates dist directory">
<echo message="Creating required directories..."/>
<mkdir dir="${dist}"/>
</target>
<target name="hibernate" depends="prepare"
description="Generates Hibernate class descriptor files.">
<taskdef name="hibernatedoclet"
classname="xdoclet.modules.hibernate.HibernateDocletTask">
<classpath>
<fileset dir="../libs/">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<!-- Execute the hibernatedoclet task -->
<hibernatedoclet
destdir="."
excludedtags="@version,@author,@todo"
force="true"
verbose="true"
mergedir="${dist}">
<fileset dir="./">
<include name="**/*.java"/>
</fileset>
<hibernate version="2.0"/>
</hibernatedoclet>
</target>
<target name="schemaexport">
<taskdef name="schemaexport" classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"/>
<schemaexport properties="hibernate.properties" quiet="no" text="no" drop="no" delimiter=";" output="schema-export.sql">
<fileset dir="./">
<include name="**/*.hbm.xml" />
</fileset>
</schemaexport>
</target>
<target name="schemaupdate">
<taskdef name="schemaupdate" classname="net.sf.hibernate.tool.hbm2ddl.SchemaUpdateTask" />
<schemaupdate properties="hibernate.properties" quiet="no">
<fileset dir="./">
<include name="**/*.hbm.xml" />
</fileset>
</schemaupdate>
</target>
<target name="about" description="about this build file" depends="init">
<echo message=" Use this format for the arguments:"/>
<echo message=" ant hibernate"/>
<echo message=" ant schemaexport"/>
<echo message=""/>
</target>
</project>
And here is my Answer.java:
Code:
package core;
public class Answer {
private String answer = null;
private boolean isCorrect = false;
private String annotation = null;
private long id;
/**
* Constructor of Class Answer
* @param a sets the field answer to a
* @param c sets isCorrect true if the anserwer is true
*/
public Answer(String a, boolean c, String annotation)
{
this.answer=a;
this.isCorrect=c;
this.annotation = annotation;
}
/**
* @hibernate.property
* @return Returns the answer.
*/
public String getAnswer() {
return answer;
}
/**
* @param answer The answer to set.
*/
public void setAnswer(String answer) {
this.answer = answer;
}
/**
* @hibernate.property
* @return Returns the isCorrect.
*/
public boolean isCorrect() {
return isCorrect;
}
/**
* @param isCorrect The isCorrect to set.
*/
public void setCorrect(boolean isCorrect) {
this.isCorrect = isCorrect;
}
/**
* @hibernate.property
* @return Returns the annotation.
*/
public String getAnnotation() {
return annotation;
}
/**
* @param annotation The annotation to set.
*/
public void setAnnotation(String annotation) {
this.annotation = annotation;
}
/**
* @hibernate.id generator-class="sequence"
* @return Returns the id.
*/
public long getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(long id) {
this.id = id;
}
}
The Answer.hbm.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="core.Answer"
>
<id
name="id"
column="id"
type="long"
>
<generator class="sequence">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Answer.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<property
name="answer"
type="java.lang.String"
update="true"
insert="true"
column="answer"
/>
<property
name="correct"
type="boolean"
update="true"
insert="true"
column="correct"
/>
<property
name="annotation"
type="java.lang.String"
update="true"
insert="true"
column="annotation"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Answer.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
As you can see I use xdoclet to generate the mappings.
At the moment the build.xml lies in the folder called "src" directly under the Project directory.
the Answer.java and Answer.hbm.xml are under the src dir in the "core" Package and because I am using Eclipse, all *.class files are in "bin".