This should be a simple question, but I do not know the answer :(.
Is it possible to generate the the sql script from following mapping?
I am trying to create some .sql and pojo files from a sample .nbm.xml.
Ant task is used. However, I got following exceptions complaining the class referenced in the mapping file does not exist. Of course, they do not exist since they are not generated yet? What is wrong with this?
ant -verbose ddlApache Ant version 1.6.5 compiled on November 2 2005
Buildfile: build.xml
Detected Java version: 1.5 in: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
Detected OS: Mac OS X
parsing buildfile /Users/zhouj0dg/usr/src/eclipse/workspace/hibernate31-prototype/build.xml with URI = file:///Users/zhouj0dg/usr/src/eclipse/workspace/hibernate31-prototype/build.xml
Project base dir set to: /Users/zhouj0dg/usr/src/eclipse/workspace/hibernate31-prototype
[property] Loading /Users/zhouj0dg/hibernate.properties
Build sequence for target(s) `ddl' is [ddl]
Complete build sequence is [ddl, ]
ddl:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2java (Generates a set of .java files)
[hibernatetool] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[hibernatetool] log4j:WARN Please initialize the log4j system properly.
[hibernatetool] An exception occurred while running exporter #2:hbm2java (Generates a set of .java files)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] Failed in building configuration when adding /Users/zhouj0dg/usr/src/eclipse/workspace/hibernate31-prototype/etc/PersonAddress.hbm.xml
[hibernatetool] org.hibernate.MappingException: Could not read mapping document from file: /Users/zhouj0dg/usr/src/eclipse/workspace/hibernate31-prototype/etc/PersonAddress.hbm.xml
[hibernatetool] org.hibernate.MappingException: class User not found while looking for property: name
[hibernatetool] java.lang.ClassNotFoundException: User
BUILD FAILED
/Users/zhouj0dg/usr/src/eclipse/workspace/hibernate31-prototype/build.xml:23: Failed in building configuration when adding /Users/zhouj0dg/usr/src/eclipse/workspace/hibernate31-prototype/etc/PersonAddress.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:226)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:242)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:94)
at org.hibernate.tool.ant.Hbm2JavaExporterTask.configureExporter(Hbm2JavaExporterTask.java:34)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:160)
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.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: org.hibernate.MappingException: Could not read mapping document from file: /Users/zhouj0dg/usr/src/eclipse/workspace/hibernate31-prototype/etc/PersonAddress.hbm.xml
at org.hibernate.cfg.Configuration.addFile(Configuration.java:274)
at org.hibernate.tool.ant.ConfigurationTask.addFile(ConfigurationTask.java:140)
... 21 more
Caused by: org.hibernate.MappingException: class User not found while looking for property: name
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2129)
at org.hibernate.cfg.HbmBinder.bindComponent(HbmBinder.java:1858)
at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:1691)
at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:422)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:336)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:271)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:142)
at org.hibernate.cfg.Configuration.add(Configuration.java:390)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:431)
at org.hibernate.cfg.Configuration.addFile(Configuration.java:271)
... 22 more
Caused by: java.lang.ClassNotFoundException: User
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1166)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1107)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:977)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:102)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:70)
... 33 more
--- Nested Exception ---
org.hibernate.MappingException: Could not read mapping document from file: /Users/zhouj0dg/usr/src/eclipse/workspace/hibernate31-prototype/etc/PersonAddress.hbm.xml
at org.hibernate.cfg.Configuration.addFile(Configuration.java:274)
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:226)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:242)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:94)
at org.hibernate.tool.ant.Hbm2JavaExporterTask.configureExporter(Hbm2JavaExporterTask.java:34)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:160)
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.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: org.hibernate.MappingException: class User not found while looking for property: name
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2129)
at org.hibernate.cfg.HbmBinder.bindComponent(HbmBinder.java:1858)
at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:1691)
at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:422)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:336)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:271)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:142)
at org.hibernate.cfg.Configuration.add(Configuration.java:390)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:431)
at org.hibernate.cfg.Configuration.addFile(Configuration.java:271)
... 22 more
Caused by: java.lang.ClassNotFoundException: User
at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1166)
at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1107)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:977)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:102)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:70)
... 33 more
Total time: 8 seconds
Quote:
<?xml version="1.0" encoding="UTF-8"?>
<project name="hibernate31-prototype" default="ddl" basedir="." >
<property file="${user.home}/hibernate.properties"/>
<property name="build.dir" value="./build" />
<path id="toolslib">
<path location="${hibernatetool.dir}/plugins/org.hibernate.eclipse_3.1.0.beta5/lib/tools/hibernate-tools.jar" />
<path location="${hibernatetool.dir}/plugins/org.hibernate.eclipse_3.1.0.beta5/lib/hibernate/hibernate3.jar" />
<path location="${hibernatetool.dir}/plugins/org.hibernate.eclipse_3.1.0.beta5/lib/tools/freemarker.jar" />
<path location="${hibernate.dir}/lib/mysql-connector-java-3.1.12-bin.jar" />
<fileset dir="${hibernate.dir}/lib">
<include name="commons-logging-1.0.4.jar" />
<include name="dom4j-1.6.1.jar" />
<include name="*.jar" />
</fileset>
</path>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib" />
<target name="ddl">
<hibernatetool destdir="${build.dir}">
<!--
<classpath>
<path location="${build.dir}" />
</classpath>
-->
<configuration configurationfile="./etc/hibernate.cfg.xml">
<fileset dir="etc">
<include name="PersonAddress.hbm.xml"/>
</fileset>
</configuration>
<hbm2java/>
<!--
<hbm2ddl
export="false"
update="false"
drop="true"
create="true"
outputfilename="db.ddl"
delimiter=";"
format="true"/>
-->
</hibernatetool>
</target>
</project>
Hibernate version:3.13
Mapping documents:
<hibernate-mapping>
<class name="Person">
<id name="id" column="personId">
<generator class="native" />
</id>
<set name="addresses" table="PersonAddress">
<key column="personId" />
<many-to-many column="addressId" unique="true"
class="Address" />
</set>
</class>
<class name="Address">
<id name="id" column="addressId">
<generator class="native" />
</id>
</class>
</hibernate-mapping>