-->
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.  [ 5 posts ] 
Author Message
 Post subject: Could not parse configuration
PostPosted: Wed May 30, 2012 2:46 am 
Newbie

Joined: Wed May 30, 2012 2:39 am
Posts: 5
Hey guys, I have serious problem:


I currently am using Eclipse IDE and trying to compile my source code but i can't*:

There is a Error below:

Code:
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.6//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.6.dtd">

<hibernate-configuration>
<session-factory>
        <!--Oracle JDBC Driver connection -->
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@foo.bar.foo.bar... :1521:ORCL</property>
        <property name="connection.username">me</property>
        <property name="connection.password">foobar</property>
        <property name="connection.pool_size">1</property>
      <!-- <property name="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property> -->
      <property name="dialect">org.hibernate.dialect.OracleDialect</property>
        <property name="show_sql">true</property>
        <property name="use_outer_join">true</property>
        <!-- Mapping files  作り方 -->
  <!-- <mapping class="entity.Employee"/> -->
        <mapping resource="/AdressFeatHibernate/src/EMP.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

     







Do you think there is any problem?
The Error I got is:

Code:


5 30, 2012 3:45:48 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.3.Final}
5 30, 2012 3:45:48 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
5 30, 2012 3:45:48 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
5 30, 2012 3:45:48 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
5 30, 2012 3:45:48 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
5 30, 2012 3:45:48 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Could not parse configuration: /hibernate.cfg.xml
Exception in thread "main" java.lang.NullPointerException
   at com.xecys.ORMapper.Exec.Execute(Exec.java:32)
   at com.xecys.ORMapper.Exec.main(Exec.java:12)





Im totally helpless so.... please help me! ><


Top
 Profile  
 
 Post subject: Re: Could not parse configuration
PostPosted: Thu May 31, 2012 2:36 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
Could not parse configuration: /hibernate.cfg.xml



this comes from following source:

Code:
protected Configuration doConfigure(InputStream stream, String resourceName) throws HibernateException {
      try {
         ErrorLogger errorLogger = new ErrorLogger( resourceName );
         Document document = xmlHelper.createSAXReader( errorLogger,  entityResolver )
               .read( new InputSource( stream ) );
         if ( errorLogger.hasErrors() ) {
            throw new MappingException( "invalid configuration", errorLogger.getErrors().get( 0 ) );
         }
         doConfigure( document );
      }
      catch (DocumentException e) {
         throw new HibernateException( "Could not parse configuration: " + resourceName, e );
      }


As you can see, the HibernateException is build by wrapping the DocumentException.
I guess you do catch the HibernateException in your application and give out just the HibernateExceptions message.
If you indeed do catch the HibernateException and call exception.printStackTrace() then you would see also the wrapped DocumentException
which will tell you more about the proper problem.
Maybe it's a encoding problem, did you really save the config file in utf-8 format?


Top
 Profile  
 
 Post subject: Re: Could not parse configuration
PostPosted: Thu May 31, 2012 3:57 am 
Newbie

Joined: Wed May 30, 2012 2:39 am
Posts: 5
thank you for your response.


I finally succeeded to get over the problem, but after that, after executing the main method "Exec.java", there is a problem as follows:

5 31, 2012 4:44:38 午後 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.3.Final}
5 31, 2012 4:44:38 午後 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
5 31, 2012 4:44:38 午後 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
5 31, 2012 4:44:39 午後 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
5 31, 2012 4:44:39 午後 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
5 31, 2012 4:44:39 午後 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
/hibernate.cfg.xml not found


Exec.java

Code:

package com.xecys.ORMapper;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class Exec {   
   public static void main(String[] args) {
      Exec ex = new Exec();
      ex.Execute();
   }
   
   public void Execute(){
      Session session = null;
        try{
           ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry();
           SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(serviceRegistry);
           session =sessionFactory.openSession();
           //Create new instance of Contact and set values in it by reading them from form object
           System.out.println("Inserting Record");
           Contact con = new Contact() ;  //MUMIN_VILLAGE mapping
           con.setAddress("123");
           con.setFirstName("567");
           session.save(con);
           System.out.println("Done");
        }catch(Exception e){
           System.out.println(e.getMessage());
        // Actual contact insertion will happen at this step
        }
   //     session.flush();
      //  session.close();
   }
}



hibernate.cfg.xml

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>
<session-factory>
        <!--Oracle JDBC Driver connection -->
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@foo.bar.foo.bar :1521:ORCL</property>
        <property name="connection.username">k</property>
        <property name="connection.password">sano</property>
        <property name="connection.pool_size">1</property>
      <!-- <property name="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property> -->
      <property name="dialect">org.hibernate.dialect.OracleDialect</property>
        <property name="show_sql">true</property>
        <property name="use_outer_join">true</property>
        <!-- Mapping files  作り方 -->
  <!-- <mapping class="entity.Employee"/> -->
         <mapping class="com.xecys.ORMapper.EMP" />

  <!--      <mapping resource="/AdressFeatHibernate/src/hibernate.cfg.xml"/>    -->
     <!--     <EMP.hbm.xml = "C:\Users\keisugano\XecysManager\AdressFeatHibernate\EMP.hbm.xml"/> -->
</session-factory>
</hibernate-configuration>

     



EMP.hbm.xml

Code:
<?xml version="1.0"  encoding='utf-8' ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="com.xecys.ORMapper.EMP" table="MUMIN_VILLAGE">
      // what is class name?
      <generator class="assigned" />
      <property name="FIRSTNAME" type="text" column="FIRSTNAME" />
      <property name="LASTNAME" type="text" column="LASTNAME" />
      <property name="ADDRESS" type="text" column="ADDRESS" />
      <property name="PHONE" type="text" column="PHONE" />
      <property name="EMAIL" type="text" column="EMAIL" />
   </class>
</hibernate-mapping>


contact.hbm.xml

Code:
<?xml version="1.0"? encoding='utf-8' >
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class name="com.xecys.ORMapper.Contact" table="MUMIN_VILLAGE">
   <id name="FIRSTNAME" type="text" column="FIRSTNAME" >
   <id name="LASTNAME" type="text" column="LASTNAME" >
   <id name="PHONE" type="text" column="PHONE" >
   <id name="EMAIL" type="text" column="EMAIL" >   
   <generator class="assigned"/>
  </id>

  <property name="FIRSTNAME">
   <column name="FIRSTNAME" />
  </property>
  <property name="LASTNAME">
   <column name="LASTNAME" />
  </property>
  <property name="PHONE">
  <column name="PHONE"/>
  </property>
  <property name="EMAIL">
  <column name="EMAIL"/>
  </property>
</class>
</hibernate-mapping>




Build.xml
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.6.dtd">



<hibernate-configuration>
<session-factory>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:oracle:thin:@foo.bar.foo.bar:1521:ORCL</property>
  <property name="hibernate.connection.username">i</property>
  <property name="hibernate.connection.password">no</property>
  <property name="hibernate.connection.pool_size">10</property>
  <property name="show_sql">true</property>
  <property name="hibernate.hbm2ddl.auto">update</property>
  <!-- Mapping files -->
  <mapping resource="/AdressFeatHibernate/src/com/xecys/ORMapper/EMP.hbm.xml"/>
  <mapping resource="/AdressFeatHibernate/src/com/xecys/ORMapper/hibernate.cfg.xml"/>
</session-factory>
</hibernate-configuration>







Is anything wrong with these codes? Actually I decided to put utf description in each of the xml tags....








Also, I have to show the Package Explorer...




[img]http://2.bp.blogspot.com/-tAx8akAU2OU/T8cmjkPeDVI/AAAAAAAACcg/jUsG2bbRgKA/s1600/bandicam%2B2012-05-31%2B17-04-27-890.jpg[/img]


Top
 Profile  
 
 Post subject: Re: Could not parse configuration
PostPosted: Fri Jun 01, 2012 2:06 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
The problem is that you put hibernate.cfg.xml in directory (package) com.xecys.ORMapper
You must put it to the root directoy.


Top
 Profile  
 
 Post subject: Re: Could not parse configuration
PostPosted: Thu Jun 07, 2012 4:57 am 
Newbie

Joined: Wed May 30, 2012 2:39 am
Posts: 5
Thank you for your support.

The issue was resolved ><


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