I'm just starting with Hibernate. I'm going through Gavin King's TSS "Introduction To Hibernate"
http://www.theserverside.com/resources/articles/Hibernate/IntroductionToHibernate.pdf document. I've modified his Team.hbm.xml and Player.hbm.xml to use Oracle sequences for IDs. I've got an Ant build script that I reuse for all my projects, so I added in a schema export Ant task that uses net.sf.hibernate.tool.hbm2ddl.SchemaExportTask, like this:
Code:
<target name="schema-export" depends="compile">
<taskdef name="schema-export"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.class.path"/>
<schemaexport properties="${src.properties}/hibernate.properties"
quiet="no"
text="yes"
drop="no"
delimiter=";"
output="${src.sql}/${project}-schema.sql">
<fileset dir="${src.properties}">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>
When I run Ant, I get the following exception:
Code:
schemaexport:
[schemaexport] Dec 17, 2003 11:44:12 AM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: Hibernate 2.1 final
[schemaexport] Dec 17, 2003 11:44:12 AM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: hibernate.properties not found
[schemaexport] Dec 17, 2003 11:44:12 AM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: using CGLIB reflection optimizer
[schemaexport] Dec 17, 2003 11:44:12 AM net.sf.hibernate.cfg.Configuration addFile
[schemaexport] INFO: Mapping file: C:\Edu\Java\Hibernate\src\properties\Player.hbm.xml
[schemaexport] Dec 17, 2003 11:44:12 AM net.sf.hibernate.cfg.Configuration add
[schemaexport] SEVERE: Could not compile the mapping document
[schemaexport] net.sf.hibernate.MappingException: persistent class [example.Player] not found
[schemaexport] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:81)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:207)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1167)
[schemaexport] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:245)
[schemaexport] at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:167)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.getConfiguration(SchemaExportTask.java:186)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:132)
[schemaexport] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[schemaexport] at org.apache.tools.ant.Task.perform(Task.java:341)
[schemaexport] at org.apache.tools.ant.Target.execute(Target.java:309)
[schemaexport] at org.apache.tools.ant.Target.performTasks(Target.java:336)
[schemaexport] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[schemaexport] at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
[schemaexport] at org.apache.tools.ant.Main.runBuild(Main.java:609)
[schemaexport] at org.apache.tools.ant.Main.start(Main.java:196)
[schemaexport] at org.apache.tools.ant.Main.main(Main.java:235)
[schemaexport] Caused by: java.lang.ClassNotFoundException: example.Player
[schemaexport] at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1075)
[schemaexport] at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1036)
[schemaexport] at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:925)
[schemaexport] at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
[schemaexport] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
[schemaexport] at java.lang.Class.forName0(Native Method)
[schemaexport] at java.lang.Class.forName(Class.java:140)
[schemaexport] at net.sf.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:75)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:78)
[schemaexport] ... 15 more
[schemaexport] Dec 17, 2003 11:44:12 AM net.sf.hibernate.cfg.Configuration addFile
[schemaexport] SEVERE: Could not configure datastore from file: C:\Edu\Java\Hibernate\src\properties\Player.hbm.xml
[schemaexport] net.sf.hibernate.MappingException: persistent class [example.Player] not found
[schemaexport] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:81)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:207)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1167)
[schemaexport] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:245)
[schemaexport] at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:167)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.getConfiguration(SchemaExportTask.java:186)
[schemaexport] at net.sf.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:132)
[schemaexport] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
[schemaexport] at org.apache.tools.ant.Task.perform(Task.java:341)
[schemaexport] at org.apache.tools.ant.Target.execute(Target.java:309)
[schemaexport] at org.apache.tools.ant.Target.performTasks(Target.java:336)
[schemaexport] at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
[schemaexport] at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
[schemaexport] at org.apache.tools.ant.Main.runBuild(Main.java:609)
[schemaexport] at org.apache.tools.ant.Main.start(Main.java:196)
[schemaexport] at org.apache.tools.ant.Main.main(Main.java:235)
[schemaexport] Caused by: java.lang.ClassNotFoundException: example.Player
[schemaexport] at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1075)
[schemaexport] at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1036)
[schemaexport] at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:925)
[schemaexport] at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
[schemaexport] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
[schemaexport] at java.lang.Class.forName0(Native Method)
[schemaexport] at java.lang.Class.forName(Class.java:140)
[schemaexport] at net.sf.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:75)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:78)
[schemaexport] ... 15 more
BUILD FAILED
file:C:/Edu/Java/Hibernate/build.xml:92: Schema text failed: net.sf.hibernate.MappingException: persistent class [exampl
e.Player] not found
I thought the exception was telling me that I had to run net.sf.hibernate.tool.hbm2java.CodeGenerator first, so I tried to find that Ant task. But I looked out on hibernate.sourceforge.net for the tools JAR, without success.
So I have two questions:
(1) What is the proper sequence? Do I have to generate Java stubs before the schema? Why does Gavin's article imply that I can generate the schema independently?
(2) Where can I find the JAR file containing net.sf.hibernate.tool.hbm2java.CodeGenerator?
Thanks very much for your help.
Code:
[url][/url]