-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: Configuration file at different location
PostPosted: Thu Mar 31, 2005 4:09 am 
Newbie

Joined: Wed Jan 05, 2005 5:30 am
Posts: 14
I cannot make hibernate read my config file stored at a specific location. I am using Hibernate 2.1

Code:
        SessionFactory sf = new Configuration()
        .configure("C:\\hibernate.cfg.xml")
        .buildSessionFactory();



Here is the error log

I have ofcourse tried with both slash and backslash?

Code:
10:03:22,921  INFO Environment:478 - Hibernate 2.1.7
10:03:22,941  INFO Environment:507 - hibernate.properties not found
10:03:22,951  INFO Environment:538 - using CGLIB reflection optimizer
10:03:22,951  INFO Environment:567 - using JDK 1.4 java.sql.Timestamp handling
10:03:22,961  INFO Configuration:900 - configuring from resource: C:\hibernate.cfg.xml
10:03:22,961  INFO Configuration:872 - Configuration resource: C:\hibernate.cfg.xml
10:03:22,971  WARN Configuration:876 - C:\hibernate.cfg.xml not found
10:03:22,981 ERROR HibernateUtil:32 - Initial SessionFactory creation failed.
net.sf.hibernate.HibernateException: C:\hibernate.cfg.xml not found


Top
 Profile  
 
 Post subject: Hibernate has an error
PostPosted: Thu Mar 31, 2005 4:20 am 
Newbie

Joined: Wed Jan 05, 2005 5:30 am
Posts: 14
Well apparently there is an error here. This way works, This is NOT how its stated in the manual.

Code:
        SessionFactory sf = new Configuration()
        .configure(new File(path+"hibernate.cfg.xml"))
        .buildSessionFactory();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 2:19 pm 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
I am trying to do something like this. I want to do something like:

Configuration().configure("test.cfg.xml");

The test.cfg.xml file is located in the same directory / package path as hibernate.cfg.xml.

This is my dump:

14:19:23,703 INFO Configuration:900 - configuring from resource: test.cgf.xml
14:19:23,703 INFO Configuration:872 - Configuration resource: test.cgf.xml
14:19:23,718 WARN Configuration:876 - test.cgf.xml not found
net.sf.hibernate.HibernateException: test.cgf.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:877)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:901)
at config.SessionManager.connect(SessionManager.java:52)
at config.ConfigTest.main(ConfigTest.java:51)

any help?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 2:23 am 
Newbie

Joined: Mon Apr 18, 2005 8:15 am
Posts: 7
weaselboy1976 wrote:
I am trying to do something like this. I want to do something like:

Configuration().configure("test.cfg.xml");

The test.cfg.xml file is located in the same directory / package path as hibernate.cfg.xml.

This is my dump:

14:19:23,703 INFO Configuration:900 - configuring from resource: test.cgf.xml
14:19:23,703 INFO Configuration:872 - Configuration resource: test.cgf.xml
14:19:23,718 WARN Configuration:876 - test.cgf.xml not found
net.sf.hibernate.HibernateException: test.cgf.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:877)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:901)
at config.SessionManager.connect(SessionManager.java:52)
at config.ConfigTest.main(ConfigTest.java:51)

any help?


!!!! You use "test.cgf.xml" instead of "test.cfg.xml
/ Anders


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 21, 2005 8:28 am 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
Sorry, that was just a typo. Actually "test.cfg.xml" is used in both places. That isn't the problem. Same error exists.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 5:41 pm 
Newbie

Joined: Wed Apr 20, 2005 4:37 pm
Posts: 6
I am receiving the same error when I specify an absolute path to the hibernate.cfg.xml file. I am running the latest Hibernate 3.0.1. Here is a section of my code.
Code:
String filename = "/web/etc/hibernate/hibernate.cfg.xml";
SessionFactory sessionFactory =
    new Configuration().configure(filename).buildSessionFactory();


I receive the following error message:

Quote:
14:24:31 - [tcp-connection-3] INFO (Configuration.configure:1160) - configuring from resource: /web/etc/hibernate/hibernate.cfg.xml
14:24:31 - [tcp-connection-3] INFO (Configuration.getConfigurationInputStream:1131) - Configuration resource: /web/etc/hibernate/hibernate.cfg.xml
14:24:31 - [tcp-connection-3] WARN (Configuration.getConfigurationInputStream:1136) - /web/etc/hibernate/hibernate.cfg.xml not found
14:24:31 - [tcp-connection-3] ERROR (HibernateSessionMgr.init:35) - Initial SessionFactory creation failed.
org.hibernate.HibernateException: /web/etc/hibernate/hibernate.cfg.xml not found


Is this a bug in Hibernate 3.0.1 or is the Configuration method .configure(String) intended for something else? I double checked the existence of the file at that location and I checked the file permissions. I am running Hibernate on Red Hat Enterprise 3 linux system.

Thanks,
Keith


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 23, 2005 10:10 am 
Beginner
Beginner

Joined: Fri Feb 04, 2005 2:44 pm
Posts: 25
Location: Buffalo, NY
Try:

SessionFactory sessionFactory =
new Configuration().configure(new File(filename)).buildSessionFactory();

keithdfetterman wrote:
I am receiving the same error when I specify an absolute path to the hibernate.cfg.xml file. I am running the latest Hibernate 3.0.1. Here is a section of my code.
Code:
String filename = "/web/etc/hibernate/hibernate.cfg.xml";
SessionFactory sessionFactory =
    new Configuration().configure(filename).buildSessionFactory();


I receive the following error message:

Quote:
14:24:31 - [tcp-connection-3] INFO (Configuration.configure:1160) - configuring from resource: /web/etc/hibernate/hibernate.cfg.xml
14:24:31 - [tcp-connection-3] INFO (Configuration.getConfigurationInputStream:1131) - Configuration resource: /web/etc/hibernate/hibernate.cfg.xml
14:24:31 - [tcp-connection-3] WARN (Configuration.getConfigurationInputStream:1136) - /web/etc/hibernate/hibernate.cfg.xml not found
14:24:31 - [tcp-connection-3] ERROR (HibernateSessionMgr.init:35) - Initial SessionFactory creation failed.
org.hibernate.HibernateException: /web/etc/hibernate/hibernate.cfg.xml not found


Is this a bug in Hibernate 3.0.1 or is the Configuration method .configure(String) intended for something else? I double checked the existence of the file at that location and I checked the file permissions. I am running Hibernate on Red Hat Enterprise 3 linux system.

Thanks,
Keith


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 24, 2005 12:06 am 
Beginner
Beginner

Joined: Wed Apr 20, 2005 9:30 am
Posts: 39
Or try Configuration().configure("/test.cfg.xml");

I read somewhere this has something to do with the class loader at hand, and in my own tests, that simple slash made a big difference.

Cheers,

J --


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 24, 2005 2:07 am 
Newbie

Joined: Wed Apr 20, 2005 4:37 pm
Posts: 6
Quote:
Or try Configuration().configure("/test.cfg.xml");

I read somewhere this has something to do with the class loader at hand, and in my own tests, that simple slash made a big difference.


In your example, does the test.cfg.xml have to be located somewhere in the classpath? In my original example, the path/config file was located outside the classpath.

Thanks,
Keith


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 24, 2005 10:59 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
Configuration.configure(String) uses classloader semantics for the String argument, not an absolute pathname. I agree, the JavaDoc could be more clear that "application resource" = classloader resource.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 24, 2005 10:59 am 
Newbie

Joined: Tue Jan 11, 2005 6:48 am
Posts: 7
Hello,

We had the same error in house for quite some time and we found a workaround for this one.


to make things work, we now use :

// -----------------------------------------------------

URL configFilePath = TheseosRepositoryAccessor.class.getResource(theConfigFilePath);

Configuration myConfiguration = new Configuration();
myConfiguration.configure(configFilePath);

hibernateFactory = myConfiguration.buildSessionFactory();

// -----------------------------------------------------


This way makes things work. It seems that configuring from an URL is a lot more easy than with a file ;-)

This should solve your problems,

Jerarckill


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.