-->
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.  [ 4 posts ] 
Author Message
 Post subject: cant generate DDL from hbm.xml using hbm2ddl tool
PostPosted: Tue Oct 05, 2004 1:44 pm 
Beginner
Beginner

Joined: Thu Jul 29, 2004 7:14 pm
Posts: 41
Hibernate version: 2.1.4

Mapping documents:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="dbdemo.Address" table="Address" dynamic-update="false">
<id name="id" column="ID" type="string" unsaved-value="any">
<generator class="assigned">
</generator>
</id>

<property name="city" type="string" update="true" insert="true" column="City"/>
<property name="state" type="string" update="true" insert="true" column="State"/>
<property name="zip" type="string" update="true" insert="true" column="Zip"/>

</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
C:\Examples\HB\NonManagedEnvironment\Meagle>ant schemaexport
Buildfile: build.xml

schemaexport:
[schemaexport] Oct 5, 2004 1:16:31 PM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: Hibernate 2.1.4
[schemaexport] Oct 5, 2004 1:16:31 PM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: loaded properties from resource hibernate.properties: {hibe
rnate.connection.driver_class=sun.jdbc.odbc.JdbcOdbcDriver, hibernate.cglib.use_
reflection_optimizer=true, hibernate.cache.provider_class=net.sf.ehcache.hiberna
te.Provider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1,
hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect, hibernate.jdbc.use_
streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substituti
ons=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibern
ate.connection.username=sa, hibernate.cache.region_prefix=hibernate.test, hibern
ate.connection.url=jdbc:odbc:Syed_Testing, hibernate.show_sql=false, hibernate.c
onnection.password=, hibernate.connection.pool_size=3}
[schemaexport] Oct 5, 2004 1:16:31 PM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: using java.io streams to persist binary types
[schemaexport] Oct 5, 2004 1:16:31 PM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: using CGLIB reflection optimizer
[schemaexport] Oct 5, 2004 1:16:31 PM net.sf.hibernate.cfg.Configuration addFile

[schemaexport] INFO: Mapping file: C:\Examples\HB\NonManagedEnvironment\Meagle\s
rc\Address.hbm.xml
[schemaexport] Oct 5, 2004 1:16:31 PM net.sf.hibernate.cfg.Configuration add
[schemaexport] SEVERE: Could not compile the mapping document
[schemaexport] net.sf.hibernate.MappingException: persistent class [Address] not
found
[schemaexport] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:84)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)
[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:269)
[schemaexport] at org.apache.tools.ant.Task.perform(Task.java:364)
[schemaexport] at org.apache.tools.ant.Target.execute(Target.java:301)
[schemaexport] at org.apache.tools.ant.Target.performTasks(Target.java:328)
[schemaexport] at org.apache.tools.ant.Project.executeTarget(Project.java:1215)

[schemaexport] at org.apache.tools.ant.Project.executeTargets(Project.java:1063
)
[schemaexport] at org.apache.tools.ant.Main.runBuild(Main.java:632)
[schemaexport] at org.apache.tools.ant.Main.startAnt(Main.java:183)
[schemaexport] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:197)
[schemaexport] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:56)
[schemaexport] Caused by: java.lang.ClassNotFoundException: Address
[schemaexport] at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
[schemaexport] at java.security.AccessController.doPrivileged(Native Method)
[schemaexport] at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
[schemaexport] at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
[schemaexport] at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
[schemaexport] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

[schemaexport] at java.lang.Class.forName0(Native Method)
[schemaexport] at java.lang.Class.forName(Class.java:141)
[schemaexport] at net.sf.hibernate.util.ReflectHelper.classForName(ReflectHelpe
r.java:102)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:81)
[schemaexport] ... 16 more
[schemaexport] Oct 5, 2004 1:16:31 PM net.sf.hibernate.cfg.Configuration addFile

[schemaexport] SEVERE: Could not configure datastore from file: C:\Examples\HB\N
onManagedEnvironment\Meagle\src\Address.hbm.xml
[schemaexport] net.sf.hibernate.MappingException: persistent class [Address] not
found
[schemaexport] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:84)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:221)
[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:269)
[schemaexport] at org.apache.tools.ant.Task.perform(Task.java:364)
[schemaexport] at org.apache.tools.ant.Target.execute(Target.java:301)
[schemaexport] at org.apache.tools.ant.Target.performTasks(Target.java:328)
[schemaexport] at org.apache.tools.ant.Project.executeTarget(Project.java:1215)

[schemaexport] at org.apache.tools.ant.Project.executeTargets(Project.java:1063
)
[schemaexport] at org.apache.tools.ant.Main.runBuild(Main.java:632)
[schemaexport] at org.apache.tools.ant.Main.startAnt(Main.java:183)
[schemaexport] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:197)
[schemaexport] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:56)
[schemaexport] Caused by: java.lang.ClassNotFoundException: Address
[schemaexport] at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
[schemaexport] at java.security.AccessController.doPrivileged(Native Method)
[schemaexport] at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
[schemaexport] at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
[schemaexport] at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
[schemaexport] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

[schemaexport] at java.lang.Class.forName0(Native Method)
[schemaexport] at java.lang.Class.forName(Class.java:141)
[schemaexport] at net.sf.hibernate.util.ReflectHelper.classForName(ReflectHelpe
r.java:102)
[schemaexport] at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:81)
[schemaexport] ... 16 more

BUILD FAILED
C:\Examples\HB\NonManagedEnvironment\Meagle\build.xml:84: Schema text failed: ne
t.sf.hibernate.MappingException: persistent class [Address] not found

Total time: 1 second
Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Hi,

I am trying to create a .sql file from my .hbm.xml file. So first I create two folders lib and src in my base folder. In lib i put these jar files :
cglib-full-2.0.1.jar
commons-collections-2.1.jar
commons-logging-1.0.3.jar
dom4j-1.4.jar
ehcache-0.7.jar
hibernate2.jar
hibernate-tools.jar
jdbc2_0-stdext.jar
jta.jar
odmg-3.0.jar
jdom.jar
velocity-1.3.1.jar

In src I create Address.hbm.xml which is listed above.
In base folder I have my hibernate.properties file which i have tested that it connects to my database. I then created my ant script build.xml which is :

<?xml version="1.0"?>

<project name="HB" default="schemaexport" basedir=".">

<!-- Set up properties containing important project directories -->
<property name="source.dir" value="src"/>
<property name="lib.dir" value="lib"/>

<!-- Set up the class path for compilation and execution -->
<path id="project.class.path">
<!-- Include jars in the project library directory -->
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="schemaexport" description="Generate the DDL statements from the O/R mapping files">

<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.class.path"/>

<schemaexport
properties="hibernate.properties"
quiet="no"
text="no"
drop="no"
delimiter=";"
output="schema-export.sql">
<fileset dir="${source.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>

</target>
</project>


When I run ant schemaexport, I am getting the error message which I have mentioned above.

Any reason?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 05, 2004 3:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you don't add your mapped classes to the class library- thus the complain about hibernate not being able to load the classes!

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 10:03 am 
Beginner
Beginner

Joined: Thu Jul 29, 2004 7:14 pm
Posts: 41
max wrote:
you don't add your mapped classes to the class library- thus the complain about hibernate not being able to load the classes!


I made this change in my build.xml

<!-- Set up the class path for compilation and execution -->
<path id="project.class.path">
<!-- Include jars in the project library directory -->
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${source.dir}">
<include name="*.hbm.xml"/>
</fileset>
</path>

But I am still getting the same error message.

In my base folder I have hibernate.properties and build.xml
In my src folder I have Address.hbm.xml
In my lib folder I have all my jar files


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 6:30 pm 
Beginner
Beginner

Joined: Thu Jul 29, 2004 7:14 pm
Posts: 41
I got it working when I put the Address.class file in my src folder and changing the build.xml to :

<!-- Set up the class path for compilation and execution -->
<path id="project.class.path">
<!-- Include jars in the project library directory -->
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<pathelement location="${source.dir}"/>
</path>

So hbm2ddl is not an independant tool that can create DDL form the hbm.xml alone. It needs the class file too. I wonder why?


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