-->
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: Running SchemaExport manually
PostPosted: Tue Mar 08, 2005 4:28 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
Hibernate version: 3.0 Beta 4

Mapping documents: eg/org/hibernate/auction/*.hbm.xml

Name and version of the database you are using: Firebird 1.5.2

I'm trying to modify the 'eg' example that ships with Hibernate 3.0 such that I can run it with Firebird.

SchemaExport cannot be done programatically, so I commented out the .setProperty(Environment.HBM2DDL_AUTO, "create"); in Main.java and I'm trying to use SchemaExport manually to create the DDL file and then figure out how to manually send it to Firebird to create the database.

I found the sample ANT target in the Hibernate Reference that ships with 3.0 and I've been trying to add it to the build.xml that ships with 3.0.

(Actually, my first attempt was to run SchemaExport via 'java ...' or via 'bin\SchemaExport.bat' but I couldn't figure out how to get the arguments right, so I thought I might have better luck tweaking the ANT target)

Anyway, this is my best guess, trying to use the properties defined in your build.xml:

-------------------------------------------------------------------------------------

<target name="schemaexport">
<taskdef name="schemaexport"
classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="lib.class.path"/>

<schemaexport
properties="etc/hibernate.properties"
quiet="no"
text="no"
drop="no"
delimiter=";"
output="schema-export.sql">
<fileset dir="eg">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>

When I run 'ant schemaexport', I get this:

-------------------------------------------------------------------------------------

D:\hibernate-3.0>ant schemaexport
Buildfile: build.xml
[taskdef] Could not load definitions from resource checkstyletask.properties. It could not be found.
[taskdef] Could not load definitions from resource clovertasks. It could not be found.

schemaexport:
[schemaexport] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[schemaexport] log4j:WARN Please initialize the log4j system properly.

BUILD FAILED
D:\hibernate-3.0\build.xml:696: Schema text failed: org.hibernate.MappingException: class org.hibernate.auction.AuctionItem not found while looking for property: id

Total time: 1 second
D:\hibernate-3.0>

-------------------------------------------------------------------------------------

Can someone help me figure out how to run this?

And if I could make a suggestion, just listing the usage of SchemaExport or an example ANT task that refers to properties that aren't defined is no help at all. It's pretty clear that I'm supposed to pass "mapping_files" as the last argument, but I can't even guess what the format of that string is supposed to be. A comma/semicolon-separated list of .hbm.xml files? A path? What?

Thanks,
-Jeff


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 5:53 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Two points you have to check

- your hibernate.properties must be in your classpath if you want schemaexport to find it by default (it seems that for your it is in the etc folder)
- Maybe you have to give a classpath attribute to the SchemaExport task in order for it to find your classes

but if you put the hibernate.properties in the classpath, running schemaexport in a main is as easy as
Code:
new SchemaExport(new Configuration().configure()).create(true, false);

you set true in the first parameter if you want to generate a script and true for the second if you want to create the database directly


Top
 Profile  
 
 Post subject: Re: Running SchemaExport manually
PostPosted: Wed Mar 09, 2005 11:41 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
scesbron wrote:
Two points you have to check

- your hibernate.properties must be in your classpath if you want schemaexport to find it by default (it seems that for your it is in the etc folder)
- Maybe you have to give a classpath attribute to the SchemaExport task in order for it to find your classes

but if you put the hibernate.properties in the classpath, running schemaexport in a main is as easy as
Code:
new SchemaExport(new Configuration().configure()).create(true, false);

you set true in the first parameter if you want to generate a script and true for the second if you want to create the database directly


I'll try playing around with classpath more. The hibernate.properties seems to get picked up from etc when I run 'ant eg', so I'll look at that task to see if anything obvious is different.

Unfortunately, I CAN'T run schemaexport in a main to Firebird, because I have to have exclusive DB access to do some of the operations and I only seem to be able to get it from the command line. That's why I've disabled this from the example and I'm trying to save the schema off to a file in hopes of sending it manually to Firebird.

-Jeff


Top
 Profile  
 
 Post subject: Re: Running SchemaExport manually
PostPosted: Wed Mar 09, 2005 12:34 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
It was definitely a classpath issue. [ Isn't everything? :-) ]

I tried to fix it in ant but gave up for now and just added hibernate's etc and eg directories to my classpath manually.

That got the ant task going. Oddly, I had not changed the text="no" in the task yet, so when SchemaExport tried to go straight to Firebird, it worked, as opposed to calling it from the main(), which resulted in 'in use' errors. Anyway, it saved me a step and with the database set up I was finally able to run the rest of the example.

-Jeff


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.