• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

hibernate.cfg.xml not found

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone,

i am a beginner to hibernate and i am having great difficulty in mapping the database. i am using jdk1.5(is it comaptible) and netbeans4.0 and hypersonic database (hsqldb 1.7.3).

whenever i run the program it does not detect either the hibernate.properties nor the hibernate.cfg.xml due to which i am unable to grasp anything about the working of hibernate.

whenever i use the command prompt for running a simple application it shows that jdbc connection not found.

can anybody help out with this.

karthik
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also had some problems with the cfg.xml file. You might be able to get it by using ClassLoader.getResource(). I ended up putting the config in the code with a Configuration object. Not sure why it wouldn't pick it up.

P.S. I am using eclipse with MySQL and Java 1.4.2.
 
karthik vraman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi steven

thanx for reply.
i will try the classloader.resource() and get back to you.

but still i want to know the reason for such variation.
has it got anything to do with the operating system?

karthik
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate will look for its configuration file using the classpath. Put the directory containing hibernate.cfg.xml in the classpath. It will look by default for your mapping files in the same package/directory that contains the mapped class file.

If you're running this through an IDE, it's apparently extremely difficult to do this. It should be a single, simple step (Project : Properties : Add Directory to Class Path) but I guess no IDE supports this which cannot be the case, so look really hard in all those dialogs.

In our Ant scripts (we don't run anything through the IDE since no application is ever deployed inside an IDE), I have it copy all properties and xml files from src and test into the classes directory which is of course in the class path.
 
karthik vraman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

whenever i run hibernate through netbeans, i am getting the following error.
i get the same error when i run through the command prompt.
i need to know whether i have to set classpath differently for hibernate.cfg.xml. i am putting this file in the source directory under the development directory.
even the corresponding jar created through compiling with netbeans records this file location, but does not detect it when run.

run:

15:48:45,905 INFO Environment:469 - Hibernate 2.1.6
15:48:45,921 INFO Environment:498 - hibernate.properties not found
15:48:45,921 INFO Environment:529 - using CGLIB reflection optimizer
15:48:45,936 INFO Configuration:895 - configuring from resource: /hibernate.cfg.xml
15:48:45,936 INFO Configuration:867 - Configuration resource: /hibernate.cfg.xml
15:48:45,936 WARN Configuration:871 - /hibernate.cfg.xml not found
Exception in thread "main" net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:872)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:896)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:883)
at test.hiber.InsertProduct.main(InsertProduct.java:27)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


The cause of error occurs at the line where we initialise transaction.
the other mechanism of using hibernate.properties file does not work as it is also not getting detected.


can anyone help me out with this trouble. i have been struck for over 4 days with this.

karthik.
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've looked at the hibernate forum and it looks like the cfg.xml file must be in the 'classes' directory not the 'source'. I assume that means where you store your binaries so it would be the bin directory for me in eclipse. I will try that later tonight when I get home and see if it works.

P.S. When the project rebuilds it may erase the cfg.xml file so keep a copy. May need to copy the file over with an ant script when building.
[ February 22, 2005: Message edited by: Steven Bell ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See Paul's post at the end of this other thread. In Eclipse there is a way to set it up so it copies files from your source directory to the classes directory after each build. Hopefully NetBeans has this feature as well.
 
Always look on the bright side of life. At least this ad is really tiny:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic