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.  [ 2 posts ] 
Author Message
 Post subject: struggling with hibernate.cfg.xml in Hibernate 4.1.6
PostPosted: Thu Aug 30, 2012 8:46 pm 
Newbie

Joined: Thu Aug 30, 2012 8:33 pm
Posts: 4
I cannot get hibernate.cfg.xml to be parsed and create a session using Hibernate 4.1.6.

Here is how I am instantiating the session:

Code:
private static Session openHibernateSession()
   {
      SessionFactory hbrntFctry;
      Session rslt = null;
      ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().configure().buildServiceRegistry();

      try
      {
         hbrntFctry = new Configuration().configure().buildSessionFactory(serviceRegistry);
         rslt = hbrntFctry.openSession();
      }
      catch (Throwable ex)
      {
         System.err.println("Failed to create sessionFactory object." + ex);
         throw new ExceptionInInitializerError(ex);
      }
      
      return rslt;
   }


Here is the file I am using:

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

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

<hibernate-configuration xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
        xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       
       
   <session-factory>
   
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

      <property name="hibernate.connection.url">jdbc:mysql://localhost/foampile</property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.connection.password"></property>
      <!-- List of XML mapping files -->
      
      <mapping resource="SiteRecord.hbm.xml"/>
      
   </session-factory>
   
</hibernate-configuration>


I modeled it after the example on the Hibernate site (http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch01.html) but their example didn't specify DOCTYPE. Some Google results I got suggested I add that so I added what was above.

What happens when I do that is this:

Code:
Caused by: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 63; Attribute "xmlns" must be declared for element type "hibernate-configuration".


and the exception is thrown on line

Code:
hbrntFctry = new Configuration().configure().buildSessionFactory(serviceRegistry);


The weird thing is that hibernate-configuration DOES in fact declare attribute "xmlns". Go figure...

When I know DOCTYPE out altogether, here is what I get:

Code:
Caused by: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 25; Document is invalid: no grammar found.


This time, the exception is thrown at the ServiceRegistry line (one line above).

Please help. I am exasperated as I have spun wheels on this last 3 hrs trying this and that, to no avail. If someone could actually post a copy of a functional cfg xml file, that would be great. As well as perhaps how the session is being created.

Thanks


Top
 Profile  
 
 Post subject: Re: struggling with hibernate.cfg.xml in Hibernate 4.1.6
PostPosted: Fri Aug 31, 2012 3:37 pm 
Newbie

Joined: Thu Aug 30, 2012 8:33 pm
Posts: 4
what i have just found out is that, when i open the XML config file in firefox, it shows the hibernate-configuration tag as follows

<hibernate-configuration xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd">

but what it show in the text editor is

<hibernate-configuration xmlns="http://www.hibernate.org/xsd/hibernate-configuration" xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

why are the two above bolded attributes in the XML file but not being parsed properly ??


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.