Solved

Hibernate configure will not read hibernate.cfg.xml file

Posted on 2006-11-16
5
244 Views
Last Modified: 2010-03-31
I have this line of code loading my hibernate.cfg.xml file

SessionFactory sessionFactory = new Configuration().setProperty("hibernate.show_sql", "true").configure("order_mod\\hibernate.cfg.xml").buildSessionFactory();
           
When i run this in my IDE Netbeans it works find however when i tried to run this from the jar file outside of the IDE through the command line java -jar order_mod.jar it gave me an error saying it could not find order_mod\\hibernate.cfg.xml

The directory of my jar file is as follows

Order_Mod.jar
  -order_mod(package)
    -someclass.java
    -someclass_Where_Hibernate_Is_Run_And_Above_Line_Of_Code_Is_Called.java
    -hibernate.cfg.xml
0
Comment
Question by:ethnarch
  • 2
  • 2
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 17960384
try:

SessionFactory sessionFactory = new Configuration().setProperty("hibernate.show_sql", "true").configure("/order_mod/hibernate.cfg.xml").buildSessionFactory();

or

SessionFactory sessionFactory = new Configuration().setProperty("hibernate.show_sql", "true").configure("hibernate.cfg.xml").buildSessionFactory();
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17962096
you should keep the folder containing "order_mod" in the classpath
0
 
LVL 2

Author Comment

by:ethnarch
ID: 17964765
objects-
  That solved my problem thanks

Ajay-
  I don't really understand what you mean if order_mod(the package) is inside my jar, then wouldn't that be inside the classpath?
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17964912
I am asking to keep the folder containing hibernate.cfg.xml (ie. order_mod) on the classpath
0
 
LVL 2

Author Comment

by:ethnarch
ID: 17967006
I still don't get it but nevermind i'll just say this

it is on the classpath according to what i layed out above in the initial question

well thankyou both for helping.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java SE 8u111  Lot of stuff broke 11 71
servlet example issue 6 40
Way to decrease size of apk file 9 71
jboss wildfly 10.1 10 101
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question