Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Hibernate configure will not read hibernate.cfg.xml file

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

856 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