Ok, I think I am closer now to getting Schema Export working but now I keep on getting this error.
Can anyone help me with this:
C:\hibernate-2.1\practice9>ant schema
Buildfile: build.xml
prepare:
compile:
schema:
[schemaexport] 03:54:53,525 INFO Environment:462 - Hibernate 2.1.4
[schemaexport] 03:54:53,619 INFO Environment:496 - loaded properties from resou
rce hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driv
er, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_clas
s=net.sf.ehcache.hibernate.Provider, hibernate.cache.use_query_cache=true, hiber
nate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect,
hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibern
ate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool
_alias=pool1, hibernate.connection.username=root, hibernate.cache.region_prefix=
hibernate.test, hibernate.hbm2ddl.auto=update, hibernate.connection.url=jdbc:mys
ql://localhost/test, hibernate.show_sql=true, hibernate.connection.password=pass
word, hibernate.connection.pool_size=1}
[schemaexport] 03:54:53,681 INFO Environment:521 - using java.io streams to per
sist binary types
[schemaexport] 03:54:53,681 INFO Environment:522 - using CGLIB reflection optim
izer
[schemaexport] 03:54:54,134 INFO Configuration:166 - Mapping file: C:\hibernate
-2.1\practice9\src\jaava\Cat.hbm.xml
[schemaexport] 03:54:55,791 INFO Binder:229 - Mapping class: jaava.Cat -> CAT
[schemaexport] 03:54:56,916 ERROR Configuration:252 - Could not compile the mapp
ing document
[schemaexport] net.sf.hibernate.MappingException: Problem trying to set property
type by reflection
[schemaexport] at net.sf.hibernate.mapping.SimpleValue.setTypeByReflection(Simp
leValue.java:183)
[schemaexport] at net.sf.hibernate.cfg.Binder.createProperty(Binder.java:1057)
[schemaexport] at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:105
0)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:361)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1243)
[schemaexport] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:249
)
[schemaexport] at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java
:171)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.getConfigurati
on(SchemaExportTask.java:195)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.execute(Schema
ExportTask.java:135)
[schemaexport] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.ja
va:275)
[schemaexport] at org.apache.tools.ant.Task.perform(Task.java:364)
[schemaexport] at org.apache.tools.ant.Target.execute(Target.java:341)
[schemaexport] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[schemaexport] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
[schemaexport] at org.apache.tools.ant.Project.executeTargets(Project.java:1062
)
[schemaexport] at org.apache.tools.ant.Main.runBuild(Main.java:673)
[schemaexport] at org.apache.tools.ant.Main.startAnt(Main.java:188)
[schemaexport] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
[schemaexport] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
[schemaexport] Caused by: net.sf.hibernate.PropertyNotFoundException: field not
found: name
[schemaexport] at net.sf.hibernate.property.DirectPropertyAccessor.getField(Dir
ectPropertyAccessor.java:74)
[schemaexport] at net.sf.hibernate.property.DirectPropertyAccessor.getField(Dir
ectPropertyAccessor.java:80)
[schemaexport] at net.sf.hibernate.property.DirectPropertyAccessor.getGetter(Di
rectPropertyAccessor.java:88)
[schemaexport] at net.sf.hibernate.util.ReflectHelper.getter(ReflectHelper.java
:81)
[schemaexport] at net.sf.hibernate.util.ReflectHelper.reflectedPropertyType(Ref
lectHelper.java:86)
[schemaexport] at net.sf.hibernate.mapping.SimpleValue.setTypeByReflection(Simp
leValue.java:172)
[schemaexport] ... 18 more
[schemaexport] 03:54:57,072 ERROR Configuration:175 - Could not configure datast
ore from file: C:\hibernate-2.1\practice9\src\jaava\Cat.hbm.xml
[schemaexport] net.sf.hibernate.MappingException: Problem trying to set property
type by reflection
[schemaexport] at net.sf.hibernate.mapping.SimpleValue.setTypeByReflection(Simp
leValue.java:183)
[schemaexport] at net.sf.hibernate.cfg.Binder.createProperty(Binder.java:1057)
[schemaexport] at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:105
0)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:361)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1243)
[schemaexport] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:249
)
[schemaexport] at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java
:171)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.getConfigurati
on(SchemaExportTask.java:195)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.execute(Schema
ExportTask.java:135)
[schemaexport] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.ja
va:275)
[schemaexport] at org.apache.tools.ant.Task.perform(Task.java:364)
[schemaexport] at org.apache.tools.ant.Target.execute(Target.java:341)
[schemaexport] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[schemaexport] at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
[schemaexport] at org.apache.tools.ant.Project.executeTargets(Project.java:1062
)
[schemaexport] at org.apache.tools.ant.Main.runBuild(Main.java:673)
[schemaexport] at org.apache.tools.ant.Main.startAnt(Main.java:188)
[schemaexport] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
[schemaexport] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
[schemaexport] Caused by: net.sf.hibernate.PropertyNotFoundException: field not
found: name
[schemaexport] at net.sf.hibernate.property.DirectPropertyAccessor.getField(Dir
ectPropertyAccessor.java:74)
[schemaexport] at net.sf.hibernate.property.DirectPropertyAccessor.getField(Dir
ectPropertyAccessor.java:80)
[schemaexport] at net.sf.hibernate.property.DirectPropertyAccessor.getGetter(Di
rectPropertyAccessor.java:88)
[schemaexport] at net.sf.hibernate.util.ReflectHelper.getter(ReflectHelper.java
:81)
[schemaexport] at net.sf.hibernate.util.ReflectHelper.reflectedPropertyType(Ref
lectHelper.java:86)
[schemaexport] at net.sf.hibernate.mapping.SimpleValue.setTypeByReflection(Simp
leValue.java:172)
[schemaexport] ... 18 more
BUILD FAILED
C:\hibernate-2.1\practice9\build.xml:113: Schema text failed: net.sf.hibernate.M
appingException: Problem trying to set property type by reflection
I would appreciate all help.
Here is the relevant code i believe that is in my build file:
<property name="source.root" value="src"/>
<property name="class.root" value="classes"/>
<property name="lib.dir" value="lib"/>
<!-- Set up the class path for compilation and execution -->
<path id="project.class.path">
<!-- Include our own classes, of course -->
<pathelement location="classes" />
<!-- Include jars in the project library directory -->
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${lib.dir}/xdoclet">
<include name="*.jar"/>
</fileset>
<pathelement location="${source.dir}" />
</path>
<target name="schema" depends="compile"
description="Generate DB schema from the O/R mapping files">
<!-- Teach Ant how to use Hibernate's schema generation tool -->
<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask" classpathref="project.class.path">
</taskdef>
<schemaexport properties="${source.root}/hibernate.properties"
quiet="no" text="no" drop="no" delimiter=";" output="schema-export.sql">
<fileset dir="src">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>
Here is my Cat.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="jaava">
<class name="Cat" table="CAT">
<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="id" type="string" unsaved-value="null" >
<column name="CAT_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="name">
<column name="NAME" length="16" not-null="true"/>
</property>
<property name="sex"/>
<!--
<column name="SEX" length="1"/>
-->
<property name="weight"/>
</class>
</hibernate-mapping>
Here is my Cat.java:
package jaava;
import java.io.Serializable;
import org.apache.commons.lang.builder.ToStringBuilder;
/** @author Hibernate CodeGenerator */
public class Cat implements Serializable {
/** identifier field */
private String id;
/** full constructor */
public Cat() {
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String toString() {
return new ToStringBuilder(this)
.append("id", getId())
.toString();
}
}
All help would be appreciated
Thx!