-->
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.  [ 3 posts ] 
Author Message
 Post subject: hibernate.cfg.xml not found
PostPosted: Tue Jun 12, 2007 12:01 pm 
Newbie

Joined: Sat Jun 09, 2007 12:36 am
Posts: 6
I have been trying to go complete my first Hibernate tutorials using eclipse and connecting to an Oracle Database.

Using Hibernate tools I have created the console configuration, the hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">XXXXXXXX</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@abcdev.iers.dta.stiop.mi.ui:1561:erddev2</property>
<property name="hibernate.connection.username">USER001</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
</session-factory>
</hibernate-configuration>

The POJO file and the XML mapping document for the table I want to read was also successfully created using Hibernate tools. I also created a class to loop through the Business table and send the Business names to the console. The code is provided below:

package gov.mt.dli.erd.clm;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class FirstExample
{
public static void main(String[] args)
{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
//session = InitSessionFactory.getInstance().getCurrentSession();

Transaction tx = session.beginTransaction();

List result = session.createQuery("from Business").list();
Iterator iter = result.iterator();
while (iter.hasNext())
{
Business aBusiness = (Business)iter.next();
System.out.println("Name: " +
aBusiness.getBusName());
}
tx.commit();
session.close();
}
}

When I try to run it I get the following error messages sent to the eclipse console:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1329)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1351)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
at gov.mt.dli.erd.clm.FirstExample.main(FirstExample.java:15)

The searches I have done on this error tell me my hibernate.cfg.xml file needs to be in the “root of my classpath”. I need confirmation on just how to do this in the eclipse environment. From the Package Explorer I have a package, Hibernate.Tutorial and have this file directly in this root. I have also tried to go through the Computer Environment variables for Classpath and but it there, but to no avail. I am new to Java and eclipse so I know I need to come up to speed in this area but, if someone would be so kind as to explain how to resolve this and if I don’t have the hibernate.cfg.xml in the right place give me a detailed explanation on how to get it there.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Tue Jun 12, 2007 1:05 pm 
Beginner
Beginner

Joined: Mon Feb 05, 2007 2:33 am
Posts: 32
if u r using java application please check the path u have given in the struts config or web.xml. This problem normally occurs due to the path is incorrect


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 1:17 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
Use Like This.... SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory(); Probably It should work.


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