• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate SchemaExport help

 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving an app off of a self done persistance layer to hibernate. I have the POJO's created, a class.hbm.xml file for each of my classes, and a hibernate.cfg.xml file with all the properties and mappings in it. I am trying to run the SchemaExport tool, but am having no luck at all. I have tried from the comand line

C:\>java -cp C:/eic/eic/hibernate-2.1 net.sf.hibernate.tool.hbm2dll.SchemaExport
--config=C:/eic/eic/src/hibernate.cfg.xml

and I get a class not found exception on the SchemaExport.

I have also tried to run it in code by creating a Configuration object, calling addFile with my cfg file and creating a SchemaExport object that way, but when I do that it doesn't seem to read in the properties.

Does anybody have any ideas?

If it would help I can post my cfg file.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steven Bell:
C:\>java -cp C:/eic/eic/hibernate-2.1 net.sf.hibernate.tool.hbm2dll.SchemaExport
--config=C:/eic/eic/src/hibernate.cfg.xml
You cannot point Java to a directory for it to slurp up all the JARs into a classpath, and you can't youse <dir>\*.jar either.

Instead, you must specify each JAR file explicitely in your classpath. Also, I don't think you can use Unix path separators for the classpath.Note that I'm just making up JAR names; you'll need to use the real ones.
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, that seems to have worked, except now it doesn't see my cfg file.

I thought you could drop jars into the %JAVA_HOME% lib\ext directory and they would get picked up.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steven Bell:
thanks, that seems to have worked, except now it doesn't see my cfg file.
This will sound like I'm contradicting myself, but you need to add the directory where the .cfg file is to the classpath. Note, however, that doing so will not make the classpath pick up the JARs.
I thought you could drop jars into the %JAVA_HOME% lib\ext directory and they would get picked up.
That will work when running your code with the JRE (though it's not highly recommended), but I don't think it affects compiling with javac. It's not recommended because it affects every Java program you run.
[ January 27, 2005: Message edited by: David Harkness ]
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java -cp C:\EIC\EIC\hibernate-2.1\hibernate2.jar;commons-logging-1.0.4.jar;dom4j-1.4.jar;C:\EIC\EIC\src net.sf.hibernate.tool.hbm2ddl.SchemaExport --config=C:\EIC\EIC\src\hibernate.cfg.xml

Ok that is what I'm typing in the command line. And I've added the path to the cfg file to my classpath in the system. But it still doesn't seem to find the file this is what I get:

Jan 27, 2005 9:36:10 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.7
Jan 27, 2005 9:36:10 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Jan 27, 2005 9:36:10 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Jan 27, 2005 9:36:10 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Jan 27, 2005 9:36:10 PM net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: C:\EIC\EIC\src\hibernate.cfg.xml
Jan 27, 2005 9:36:10 PM net.sf.hibernate.cfg.Configuration getConfigurationInput
Stream
INFO: Configuration resource: C:\EIC\EIC\src\hibernate.cfg.xml
Jan 27, 2005 9:36:10 PM net.sf.hibernate.cfg.Configuration getConfigurationInput
Stream
WARNING: C:\EIC\EIC\src\hibernate.cfg.xml not found
Jan 27, 2005 9:36:10 PM net.sf.hibernate.tool.hbm2ddl.SchemaExport main
SEVERE: Error creating schema
net.sf.hibernate.HibernateException: C:\EIC\EIC\src\hibernate.cfg.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Config
uration.java:877)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:901)
at net.sf.hibernate.tool.hbm2ddl.SchemaExport.main(SchemaExport.java:275
)
net.sf.hibernate.HibernateException: C:\EIC\EIC\src\hibernate.cfg.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Config
uration.java:877)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:901)
at net.sf.hibernate.tool.hbm2ddl.SchemaExport.main(SchemaExport.java:275
)

Anybody have any ideas, I really appreciate the help. It's gotten me this far, but I just can't seem to get this to work.

And I have double/triple checked that the file is there. I even wrote a short piece of code that created it as a file and tested to see that it was a file, came back true.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steven Bell:
Jan 27, 2005 9:36:10 PM net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: C:\EIC\EIC\src\hibernate.cfg.xml
This line certainly makes it look like it did find your configuration file. I'm curious, what happens if you move that file out of he directory. Do you get the same set of logging messages? It could be that the line above means it's going to try that file to see if it exists, but I don't read it that way.

If you get a different set of log messages, my guess is that one of the mapping files inside hibernate.cfg.xml is pointing to a non-existent file. The files it points to don't need to be on the classpath, but they do need to exist.

If neither of those pan out, I'd start digging into the Hibernate source and find where those log msgs are being emitted. That might help you figure out what the problem is.
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I tried moving the cnf file around (and changing the cp while doing it), but that didn't seem to change anything.

Guess I'll either start digging through the source, or just build the DB by hand. If all else fails I can allways do the config in the code. Just would hate to have to do that.

Thanks for all the help.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, here's another option: use Configuration's configure(File) method by creating a File with the full path to your config file and passing it in.

Wow, it's late. That made no sense since this isn't your code!
[ January 28, 2005: Message edited by: David Harkness ]
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Harkness:
Okay, here's another option: use Configuration's configure(File) method by creating a File with the full path to your config file and passing it in.

Wow, it's late. That made no sense since this isn't your code!

[ January 28, 2005: Message edited by: David Harkness ]


Thanks, but that was one of the first things I tried when the command line didn't work.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure exactly how you tried that since you're running the export tool (i.e. you aren't coding up the configuration-loading code), so I may be recommending what you've already tried.

Can you write a short class that just loads your configuration using the Hibernate API? Just to test that you can make it find the file and related mapping files. My apologies if that's what you tried already, but if so, did it work?
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is what I tried already.

Made a 'Loader' class that grabbed the cfg file. The weird thing was when I created a File object and called isFile() it returned true, but when I passed it to a Configuration object and then to the SchemaExport it didn't read in any of the configurations.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds to me like it's having trouble finding the mapping files that the main configuration file points to. Can you post your main config file? Have you verified that all mapping files it references exist where they should?
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I still don't know what is going on with my cfg file, but I finally got the DB built. I hard coded all the properties and mappings out of my cfg file into the previously mentioned Loader class. Used that Configuration object to make a new SchemaExport object anc called create() on it. I'm still just baffled as to why it didn't work from the command line.

Oh, well that is over with for now. Thanks everybody for the help.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic