-->
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.  [ 6 posts ] 
Author Message
 Post subject: Could not parse configuration: /hibernate.cfg.xml
PostPosted: Sat Sep 19, 2009 12:35 am 
Newbie

Joined: Sat Sep 19, 2009 12:25 am
Posts: 7
Hi all,

I am new with Hibernate. When I try to run it, i get the following error:
Code:
Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
   at com.vaannila.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
   at com.vaannila.course.Main.saveCourse(Main.java:22)
   at com.vaannila.course.Main.main(Main.java:16)
Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
   at com.vaannila.util.HibernateUtil.<clinit>(HibernateUtil.java:10)
   ... 2 more
Caused by: org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net
   at org.dom4j.io.SAXReader.read(SAXReader.java:484)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1532)
   ... 5 more


below is my hibernate.cgf.xml:
Code:
<?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">org.hsqldb.jdbcDriver</property>
      <property name="hibernate.connection.url">jdbc:hsqldb:mem:.</property>
      <property name="hibernate.connection.username">sa</property>
      <property name="connection.password"></property>
      <property name="connection.pool_size">1</property>
      <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
      <property name="show_sql">true</property>
      <property name="hbm2ddl.auto">create</property>
      <mapping resource="com/vaannila/course/Course.hbm.xml"/>
   </session-factory>
</hibernate-configuration>


Below is my HibernateUtil.java:
Code:
package com.vaannila.util;

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

public class HibernateUtil {
   private static final SessionFactory sessionFactory;
   static {
      try {
         sessionFactory = new Configuration().configure().buildSessionFactory();
      }catch (Throwable ex) {
         System.err.println("Initial SessionFactory creation failed." + ex);
         throw new ExceptionInInitializerError(ex);
      }
   }
   
   public static SessionFactory getSessionFactory() {
      return sessionFactory;
   }
}


Below is my Main class:
Code:
package com.vaannila.course;

import java.util.List;
import java.util.Iterator;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.vaannila.util.HibernateUtil;

public class Main {

   public static void main(String[] args) {
      Main obj = new Main();
      obj.saveCourse("Physics");
      obj.saveCourse("Chemistry");
      obj.saveCourse("Maths");
   }
   
   public Long saveCourse(String courseName){
      Session session = HibernateUtil.getSessionFactory().openSession();
      Transaction transaction = null;
      Long courseId = null;
      try {
         transaction = session.beginTransaction();
         Course course = new Course();
         course.setCourseName(courseName);
         courseId = (Long) session.save(course);
         transaction.commit();
      }catch (HibernateException e) {
         transaction.rollback();
         e.printStackTrace();
      }finally {
         session.close();
      }
      return courseId;
   }
}


Top
 Profile  
 
 Post subject: Re: Could not parse configuration: /hibernate.cfg.xml
PostPosted: Sat Sep 19, 2009 4:33 am 
Beginner
Beginner

Joined: Sat Aug 01, 2009 5:28 am
Posts: 42
i think u have problem in this line
<property name="hibernate.connection.url">jdbc:hsqldb:mem:.</property>

if u r using any ide better u validate u r xml file before running it

_________________
Warm Regards,
Tarun Walia


Top
 Profile  
 
 Post subject: Re: Could not parse configuration: /hibernate.cfg.xml
PostPosted: Sat Sep 19, 2009 7:13 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Can you verify that the tool can actually find your config file? Maybe it can't even find the file?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Could not parse configuration: /hibernate.cfg.xml
PostPosted: Sun Sep 20, 2009 4:12 am 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi suigion,

you will have to prepend hibernate to the name of each property where it currently does not appear such that your hibernate.cfg.xml looks something like this:
Code:
<?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">org.hsqldb.jdbcDriver</property>
      <property name="hibernate.connection.url">jdbc:hsqldb:mem:.</property>
      <property name="hibernate.connection.username">sa</property>
      <property name="hibernate.connection.password"></property>
      <property name="hibernate.connection.pool_size">1</property>
      <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
      <property name="hibernate.show_sql">true</property>
      <property name="hibernate.hbm2ddl.auto">create</property>
      <mapping resource="com/vaannila/course/Course.hbm.xml"/>
   </session-factory>
</hibernate-configuration>


You find an overview on constant field values at https://www.hibernate.org/hib_docs/v3/api/org/hibernate/cfg/Environment.html.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: Could not parse configuration: /hibernate.cfg.xml
PostPosted: Sun Sep 20, 2009 4:28 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Froestel wrote:
Hi suigion,
you will have to prepend hibernate to the name of each property


No, you don't.

Code:
"http://hibernate.sourceforge.net/ hibernate-configuration-3.0.dtd"


That's the problem, you have a space in the URI between ".net/" and "hibernate-". Your XML parser asks Hibernate for this DTD and Hibernate says it can't find it in the hibernate3.jar locally (because of the space). Then your XML parser tries to load it online from sourceforge.net because this URI looks like an HTTP URL. Yes, that's a pretty stupid thing to do but that's how XML parsers work these days. Now that fails because you are behind a traffic filtering firewall or simply because sourceforge.net also doesn't know what "<space>hibernate-configuration..." is supposed to be.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Re: Could not parse configuration: /hibernate.cfg.xml
PostPosted: Tue Sep 22, 2009 2:42 am 
Beginner
Beginner

Joined: Sat Aug 01, 2009 5:28 am
Posts: 42
Cameron McKenzie wrote:
Can you verify that the tool can actually find your config file? Maybe it can't even find the file?

hi Cameron,
Is there any problem if u use the tool xml parser..... or anything else?
the motive is to find the error and to correct that.isn't it

_________________
Warm Regards,
Tarun Walia


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