-->
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.  [ 4 posts ] 
Author Message
 Post subject: hibernate.cfg.xml not found
PostPosted: Mon Apr 11, 2011 5:47 pm 
Newbie

Joined: Mon Apr 11, 2011 5:37 pm
Posts: 1
hello guys,

I am trying to configure hibernate.cfg.xml in my project java, but i am not going very well. i am seeing, not found.

the path where is my hibernate.cfg.xml is: /myproject/resources/main/hibernate/hibernate.cfg.xml

resources/main is a source folder.

I tried:
Code:
   private static SessionFactory sessionFactory = new AnnotationConfiguration()
         .configure("/resources/main/hibernate/hibernate.cfg.xml").buildSessionFactory();


but it is not working. =/

any suggestions?

thanks :D


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Wed Apr 13, 2011 7:01 am 
Newbie

Joined: Wed Apr 13, 2011 6:37 am
Posts: 4
Be sure of that if it is the right path.


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Wed Apr 13, 2011 7:48 am 
Regular
Regular

Joined: Fri Nov 12, 2010 4:13 am
Posts: 81
Location: India
camilolopes wrote:
Code:
   private static SessionFactory sessionFactory = new AnnotationConfiguration()
         .configure("/resources/main/hibernate/hibernate.cfg.xml").buildSessionFactory();



Try below code,Hope it will help you.

Code:
private String _configFilePath = "/hibernate.cfg.xml";

String configFileURL=
                (String)servlet.getServletContext().getRealPath("/") + _configFilePath ;
Configuration configuration = (new Configuration()).configure(configFileURL);
private SessionFactory _factory = configuration.buildSessionFactory();


Let me know if it is working or not

_________________
Thanks & Regards,
Chirag


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Wed Apr 13, 2011 7:13 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
the path where is my hibernate.cfg.xml is: /myproject/resources/main/hibernate/hibernate.cfg.xml

resources/main is a source folder.


You don't have to give hibernate the path relative to your project but to the resources

.configure("/hibernate/hibernate.cfg.xml")

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.