Solved

Hibernate configure will not read hibernate.cfg.xml file

Posted on 2006-11-16
5
228 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now