-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Cannot compile Mapping File
PostPosted: Thu Oct 07, 2004 7:00 am 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
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!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 07, 2004 4:38 pm 
Beginner
Beginner

Joined: Thu Jul 29, 2004 7:14 pm
Posts: 41
your ant script is all screwed up. better read the manual first.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 09, 2004 6:49 pm 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
actually not really,
it was just the mapping file didn't exactly match the java file even though it was the java file that was geenrated from mapping file


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 13, 2004 9:21 am 
Beginner
Beginner

Joined: Thu Jul 29, 2004 7:14 pm
Posts: 41
In your ant script you sometimes uses "source.root" or "source.dir". Sometimes you uses the value of the property instead of the name as a reference (for example <pathelement location="classes" /> ); what is the point in defining the property then?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 18, 2004 5:06 am 
Regular
Regular

Joined: Thu Aug 05, 2004 11:15 pm
Posts: 50
Hmmmm, that is a good point. I am having some problems with the Hibernate Doclet tool. I only added some simple code to my build file but it is not exactly working. Here is the code I added to my build file:



<taskdef name="hibernatedoclet" classname="xdoclet.modules.hibernate.HibernateDocletTask" classpathref="project.class.path"/>

<target name="generate" description="Generates Hibernate class descriptor files." depends="compile">
<!-- Define the hibernatedoclet task -->


<!-- Execut the hibernatedoclet task -->
<hibernatedoclet
destdir="${jaaaava.dir}"
excludedtags="@version,@author,@todo"
force="true"
mergedir="${jaaaava.dir}"
>

<fileset dir="${source.root}">
<include name="**/*.java"/>
</fileset>

<hibernate version="2.0"/>

</hibernatedoclet>
</target>




This is the output I get:

C:\hibernate-2.1\practice9>ant generate
Buildfile: build.xml

prepare:

compile:

generate:
[hibernatedoclet] INFO: Some classes refer to other classes that were not fou
nd among the sources or on the classpath.
[hibernatedoclet] (Perhaps the referred class doesn't exist? Hasn't bee
n generated yet?)
[hibernatedoclet] The referring classes do not import any fully qualifi
ed classes matching these classes.
[hibernatedoclet] However, since no packages are imported, xjavadoc has
assumed that the referred classes
[hibernatedoclet] belong to the same package as the referring class. Th
e classes are:
[hibernatedoclet] C:\hibernate-2.1\practice9\src\net\sf\hibernate\cache\ReadWrit
eCache.java --> SoftLock qualified to net.sf.hibernate.cache.SoftLock
[hibernatedoclet] C:\hibernate-2.1\practice9\src\net\sf\hibernate\collection\Sor
tedSet.java --> SetProxy qualified to net.sf.hibernate.collection.SetProxy

BUILD SUCCESSFUL
Total time: 51 seconds



What I wanted to do is create the mapping file from the class file. So I created a random folder in my src folder and put a java file for example Track.java in there, and I would like it to create the mapping file. I created a random folder in src called jaaaava which I believe the hibernate doclet tool would put the mapping files. However I get this weird output. It says I don't import package and it doesn't read the class files I want it to generate code for.

Can anyone help me with this?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.