I am trying to generate java code from a very simple mapping file, but fails.
As you see from the output from ant, it manage to find the Events.hbm.xml file (otherwise he wouldn't know about the mapping Event -> EVENTS)
but then he dies when he stumbles on the property id.
I have been sitting here for hours trying to figure out why it doesn't work (have tried numerous things without success).
My guess would be that my mapping file is not correct, but I cannot see any errors.
I am using the latest versions of hibernate and tools (downloaded yesterday)
I would be greatful for any help on this!
the output from ant:
Code:
$ ant
Buildfile: build.xml
codegen:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2java (Generates a set of .java files)
[hibernatetool] 26-Oct-2005 00:41:09 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: Hibernate 3.1 rc2
[hibernatetool] 26-Oct-2005 00:41:09 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: hibernate.properties not found
[hibernatetool] 26-Oct-2005 00:41:09 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: using CGLIB reflection optimizer
[hibernatetool] 26-Oct-2005 00:41:09 org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: using JDK 1.4 java.sql.Timestamp handling
[hibernatetool] 26-Oct-2005 00:41:10 org.hibernate.cfg.Configuration addFile
[hibernatetool] INFO: Reading mappings from file: D:\in\java\src\Event.hbm.xml
[hibernatetool] 26-Oct-2005 00:41:10 org.hibernate.cfg.HbmBinder bindRootPersist
entClassCommonValues
[hibernatetool] INFO: Mapping class: Event -> EVENTS
BUILD FAILED
D:\in\java\build.xml:57: Failed in building configuration when adding D:\in\java
\src\Event.hbm.xml
Total time: 1 second
My build file
Code:
....
<hibernatetool destdir="output">
<configuration>
<fileset dir="src">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2java/> <!-- generate default .java files -->
</hibernatetool>
....
My mapping file
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
</class>
</hibernate-mapping>
The trace from ant says
Code:
...
[hibernatetool] 26-Oct-2005 00:59:20 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
[hibernatetool] INFO: Mapping class: Event -> EVENTS
Finding class org.hibernate.mapping.Column
Loaded from D:\temp\hibernate-3.1\hibernate3.jar org/hibernate/mapping/Column.class
Finding class org.hibernate.mapping.Selectable
Loaded from D:\temp\hibernate-3.1\hibernate3.jar org/hibernate/mapping/Selectable.class
Class org.hibernate.mapping.Selectable loaded from ant loader (parentFirst)
Class org.hibernate.mapping.Column loaded from ant loader (parentFirst)
Finding class org.hibernate.util.ReflectHelper
Loaded from D:\temp\hibernate-3.1\hibernate3.jar org/hibernate/util/ReflectHelper.class
Class org.hibernate.util.ReflectHelper loaded from ant loader (parentFirst)
Class java.lang.reflect.Member loaded from parent loader (parentFirst)
Finding class org.hibernate.PropertyNotFoundException
Loaded from D:\temp\hibernate-3.1\hibernate3.jar org/hibernate/PropertyNotFoundException.class
Class org.hibernate.PropertyNotFoundException loaded from ant loader (parentFirst)
Finding class org.hibernate.property.PropertyAccessor
Loaded from D:\temp\hibernate-3.1\hibernate3.jar org/hibernate/property/PropertyAccessor.class
Class org.hibernate.property.PropertyAccessor loaded from ant loader (parentFirst)
Finding class org.hibernate.property.BasicPropertyAccessor
Loaded from D:\temp\hibernate-3.1\hibernate3.jar org/hibernate/property/BasicPropertyAccessor.class
Class org.hibernate.property.BasicPropertyAccessor loaded from ant loader (parentFirst)
Finding class org.hibernate.property.Getter
Loaded from D:\temp\hibernate-3.1\hibernate3.jar org/hibernate/property/Getter.class
Class org.hibernate.property.Getter loaded from ant loader (parentFirst)
Finding class org.hibernate.property.Setter
Loaded from D:\temp\hibernate-3.1\hibernate3.jar org/hibernate/property/Setter.class
Class org.hibernate.property.Setter loaded from ant loader (parentFirst)
Finding class org.hibernate.property.DirectPropertyAccessor
Loaded from D:\temp\hibernate-3.1\hibernate3.jar org/hibernate/property/DirectPropertyAccessor.class
Class org.hibernate.property.DirectPropertyAccessor loaded from ant loader (parentFirst)
Class java.lang.NoSuchFieldException loaded from parent loader (parentFirst)
Finding class Event
Finding class Event
Finding class Event
Finding class org.hibernate.exception.ExceptionUtils
Loaded from D:\temp\hibernate-3.1\hibernate3.jar org/hibernate/exception/ExceptionUtils.class
Class org.hibernate.exception.ExceptionUtils loaded from ant loader (parentFirst)
Class java.lang.reflect.Field loaded from parent loader (parentFirst)
BUILD FAILED
D:\in\java\build.xml:57: Failed in building configuration when adding D:\in\java\src\Event.hbm.xml
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.java:145)
at org.hibernate.tool.ant.ConfigurationTask.addMappings(ConfigurationTask.java:123)
at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(ConfigurationTask.java:109)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:180)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:196)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:90)
at org.hibernate.tool.ant.Hbm2JavaGeneratorTask.configureExporter(Hbm2JavaGeneratorTask.java:37)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:38)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:144)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
at org.apache.tools.ant.Main.runBuild(Main.java:673)
at org.apache.tools.ant.Main.startAnt(Main.java:188)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
Caused by: org.hibernate.MappingException: Could not read mapping document from file: D:\in\java\src\Event.hbm.xml
at org.hibernate.cfg.Configuration.addFile(Configuration.java:263)
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.java:140)
... 19 more
Caused by: org.hibernate.MappingException: class Event not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:80)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:367)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:300)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:239)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:110)
at org.hibernate.cfg.Configuration.add(Configuration.java:379)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:418)
at org.hibernate.cfg.Configuration.addFile(Configuration.java:260)
... 20 more
Caused by: java.lang.ClassNotFoundException: Event
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1149)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1090)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:960)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:76)
... 28 more
--- Nested Exception ---
org.hibernate.MappingException: Could not read mapping document from file: D:\in\java\src\Event.hbm.xml
at org.hibernate.cfg.Configuration.addFile(Configuration.java:263)
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.java:140)
at org.hibernate.tool.ant.ConfigurationTask.addMappings(ConfigurationTask.java:123)
at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(ConfigurationTask.java:109)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:180)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:196)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:90)
at org.hibernate.tool.ant.Hbm2JavaGeneratorTask.configureExporter(Hbm2JavaGeneratorTask.java:37)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:38)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:144)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
at org.apache.tools.ant.Main.runBuild(Main.java:673)
at org.apache.tools.ant.Main.startAnt(Main.java:188)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
Caused by: org.hibernate.MappingException: class Event not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:80)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:367)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:300)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:239)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:110)
at org.hibernate.cfg.Configuration.add(Configuration.java:379)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:418)
at org.hibernate.cfg.Configuration.addFile(Configuration.java:260)
... 20 more
Caused by: java.lang.ClassNotFoundException: Event
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1149)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1090)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:960)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:76)
... 28 more
Total time: 1 second