-->
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.  [ 10 posts ] 
Author Message
 Post subject: Problem With SchemaExportTask and CodeGenerator
PostPosted: Wed Dec 17, 2003 2:26 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
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]

_________________
MOD


Top
 Profile  
 
 Post subject: Re: Problem With SchemaExportTask and CodeGenerator
PostPosted: Wed Dec 17, 2003 2:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
duffymo wrote:
(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?

Java classes are needed to generate the schema, since some types need to be found by introspection.

duffymo wrote:
(2) Where can I find the JAR file containing net.sf.hibernate.tool.hbm2java.CodeGenerator?


download hibernate-extensions-x.x.x.* from sourceforge

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 2:44 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
Thanks for your prompt reply, Emmanuel.

I'm a bozo - I rooted around with Google some more and found a page that pointed me back to Sourceforge! I'm downloading the tools extensions now.

So the proper ordering of Ant tasks should be:

(1) generate Java code stubs,
(2) incrementally update schema,
(3) compile Java code,
(4) JUnit tests,
(5) etc.

Correct? I've already got an Ant build.xml that does tasks (3) and on. I want to make sure that prepending the code generation and schema tasks is the right thing. Thank you.

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 2:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
SchemaExport needs compiled classes.
BTW I personnaly prefer the top down approch using xdoclet (hbm are generated)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 3:05 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
epbernard wrote:
SchemaExport needs compiled classes.
BTW I personnaly prefer the top down approch using xdoclet (hbm are generated)


Thanks, Emmanuel. I agree with you.

Eventually I'd like to go down the XDoclet path, too. I'd like to have as much code generated as possible. But today I'm still climbing that Hibernate learning curve, so I thought I'd follow through the King article as best I could until I had it under my belt. XDoclet feels like one more new thing to learn. I'd like to put Hibernate struggles behind me first. Thanks.

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 3:08 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Just a note: The article is not written by Gavin, but by Nick Heudecker. He even has an updated version here:

http://www.systemmobile.com/articles/hi ... _intro.php

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 3:08 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
Thinking more about what you said, Emmanual, are you saying that I'd be better off writing the Java stubs myself, including XDoclet tags for generating the hbm.xml files, and then having Ant generate them and the schema?

The order is flipped. Gavin King's article starts with the hbm.xml files and generates the .java stubs. You're recommending writing the .java with XDoclet tags and generating the hbm.xml files. Yes? - MOD

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 3:13 pm 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
christian wrote:
Just a note: The article is not written by Gavin, but by Nick Heudecker. He even has an updated version here:

http://www.systemmobile.com/articles/hi ... _intro.php


Thanks for correcting me, Christian. I'll give it a look.

_________________
MOD


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 7:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
duffymo wrote:
You're recommending writing the .java with XDoclet tags and generating the hbm.xml files. Yes? - MOD

I do not recommend it, I do it (which is more important ;-)).
I consider XDoclet support better and more suittable for the way I design my solutions. Java IDEs are more mature than hbm ones.
There isn't one way, but for brand new projects, I like the top down approch.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 9:32 am 
Beginner
Beginner

Joined: Wed Dec 17, 2003 10:13 am
Posts: 33
Thanks, Emmanuel, I'm doing it your way now. I just needed to know the proper idiom. - MOD

_________________
MOD


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.