-->
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.  [ 7 posts ] 
Author Message
 Post subject: org.hibernate.HibernateException: Could not parse configurat
PostPosted: Tue Feb 26, 2008 12:32 am 
Newbie

Joined: Tue Feb 26, 2008 12:20 am
Posts: 3
I am using 3.2 and have configured my tutorial project in Eclipse (with JDK 1.4). I validated the hibernate.cfg.xml and its fine. I am using dom4j-1.6.1.jar and I am getting the following errors. Any help??

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
The last line: http://hibernate.sourceforge.net/hibern ... on-3.0.dtd is where its failing with null pointer exception.

    Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
    java.lang.ExceptionInInitializerError
    at util.HibernateUtil.<clinit>(HibernateUtil.java:21)
    at events.EventManager.createAndStoreEvent(EventManager.java:24)
    at events.EventManager.main(EventManager.java:18)
    Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
    at util.HibernateUtil.<clinit>(HibernateUtil.java:14)
    ... 2 more
    Caused by: org.dom4j.DocumentException: Error on line 5 of document : java.lang.NullPointerException Nested exception: java.lang.NullPointerException
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408)
    ... 5 more
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 12:29 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Looks like hibernate.cfg.xml is in classpath. Add this file right under the src directory (out side of any package). Or else mention its path like
Code:
new Configuration().configure("/src/com/abc/myhibernate.cfg.xml");


If you still have problems, post your HibernateUtil.java code and mention the location of hibernate.cfg.xml in your project.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 1:14 pm 
Newbie

Joined: Tue Feb 26, 2008 12:20 am
Posts: 3
Hi,
Here is my code:
Code:
package util;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil
{

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
           System.err.println("Exception stack Trace ************** begin");
           ex.printStackTrace();
           System.err.println("Exception Stack Trace ********* END");
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

}

Quote:
And here is the code for hibernate.cfg.xml :

Code:

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>

        <mapping resource="events/Event.hbm.xml"/>
    </session-factory>

</hibernate-configuration>


Thanks!
-rk


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 26, 2008 1:31 pm 
Newbie

Joined: Tue Feb 26, 2008 12:20 am
Posts: 3
And the hibernate.cfg.xml is every possible place. its right under the bin (compiled class folder) and I also put it at other places. The file is being read, just its having an issue with parsing (thats what I think).

Thanks!


Top
 Profile  
 
 Post subject: hibernate-cfg.xml file now found
PostPosted: Thu Sep 25, 2008 5:53 am 
Newbie

Joined: Thu Sep 25, 2008 5:46 am
Posts: 5
Hi All

I am new to java and working on web servics using hibernate. I am working ont the existing code and imported the code in eclipse IDE using existing project but when i run the application it raise an exception for my

"hibernat-cfg-xml" file not found.
My directory Structure is

Application
-src
Myfile.java
-confg
- *.* cfg files
- *.*hbm files
-lib

Myfile.java using cfg file to build session factory. like below
queueSessionFactory = new Configuration().configure("queue.cfg.xml").buildSessionFactory();

but it says could not found queue.cfg.xml

Do i require to make some settings so that compiler will came to know to find the configurations files in the config folder.

"import org.apache.log4j.Logger;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.sprasia.entity.encode.QueueBean;"

I am importing all these libraries.


Any help would be appriciated.

-Thanks


Top
 Profile  
 
 Post subject: hibernate-cfg.xml file not found
PostPosted: Thu Sep 25, 2008 5:54 am 
Newbie

Joined: Thu Sep 25, 2008 5:46 am
Posts: 5
Hi All

I am new to java and working on web servics using hibernate. I am working ont the existing code and imported the code in eclipse IDE using existing project but when i run the application it raise an exception for my

"hibernat-cfg-xml" file not found.
My directory Structure is

Application
-src
Myfile.java
-confg
- *.* cfg files
- *.*hbm files
-lib

Myfile.java using cfg file to build session factory. like below
queueSessionFactory = new Configuration().configure("queue.cfg.xml").buildSessionFactory();

but it says could not found queue.cfg.xml

Do i require to make some settings so that compiler will came to know to find the configurations files in the config folder.

"import org.apache.log4j.Logger;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.sprasia.entity.encode.QueueBean;"

I am importing all these libraries.


Any help would be appriciated.

-Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 8:25 am 
Beginner
Beginner

Joined: Thu Jun 14, 2007 4:33 am
Posts: 39
mudgil.gaurav
i dont get your description of your structure, but i guess its like:
Code:
Application
-src
    Myfile.java
-confg
    *.* cfg files
    *.*hbm files
-lib


so your "queue.cfg.xml" its located in the confg dir? try
queueSessionFactory = new Configuration().configure("confg/queue.cfg.xml").buildSessionFactory();
as this ist the correct path to the file :/ this implies that your setup copies the confg-dir to the output-directory..


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