-->
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.  [ 1 post ] 
Author Message
 Post subject: Could not parse mapping document from resource
PostPosted: Wed Jul 11, 2012 7:50 am 
Newbie

Joined: Wed Jul 11, 2012 7:35 am
Posts: 1
I am new to hibernate and I am trying to use it with oracle 12c database. My hibernate.cfg.xml is like:-
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="dialect">org.hibernate.dialect.Oracle12cDialect</property>
    <property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
    <property name="connection.username">system</property>
    <property name="connection.password">*******</property>

    <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>

    <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="current_session_context_class">thread</property>
    <property name="hibernate.show_sql">true</property>
   
   <!-- Mapping files -->
   <mapping resource="NCS_User.hbm.xml"/>
  </session-factory>

</hibernate-configuration>


My NCS_User.hbm.xml:-
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class name="TestHibernate.NCS_User" table="NCS_User">
   <id name="ROLEID" type="long" column="ROLEID" >
   <generator class="assigned"/>
  </id>

  <property name="FULLNAME">
   <column name="FULLNAME" />
  </property>
  <property name="PERSONIDNO">
  <column name="PERSONIDNO"/>
  </property>
  <property name="ROLENAME">
  <column name="ROLENAME"/>
  </property>
  <property name="SCHEMEID">
  <column name="SCHEMEID"/>
  </property>
  <property name="SCHEMETITLE">
  <column name="SCHEMETITLE"/>
  </property>
</class>
</hibernate-mapping>


My code for NCS_User.java:-
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testhibernate;


/**
*
* @author Administrator
*/
public class NCS_User {

   private String PERSONIDNO;
        private String FULLNAME;
        private int ROLEID;
        private String ROLENAME;
        private int SCHEMEID;
        private String SCHEMETITLE;

   /**
    * creates the system default users [only used by spring]
    *
    * @param PERSONIDNO
    * @param FULLNAME
    * @param ROLEID
    * @param ROLENAME
    * @param SCHEMEID
    * @param SCHEMETITLE
    */
   private NCS_User(final int ROLEID) {
      this.ROLEID = ROLEID;
   }

   public String getFULLNAME() {
      return FULLNAME;
   }

   public int getROLEID() {
      return ROLEID;
   }

   public String getROLENAME() {
      return ROLENAME;
   }

   public int getSCHEMEID() {
      return SCHEMEID;
   }

   public String getSCHEMETITLE() {
      return SCHEMETITLE;
   }
       
   public String getPERSONIDNO() {
      return PERSONIDNO;
   }

   public void setFULLNAME(final String FULLNAME) {
      this.FULLNAME = FULLNAME;
   }

   public void setROLEID(final int ROLEID) {
      this.ROLEID = ROLEID;
   }

   public void setROLENAME(final String ROLENAME) {
      this.ROLENAME = ROLENAME;
   }

   public void setSCHEMEID(final int SCHEMEID) {
      this.SCHEMEID = SCHEMEID;
   }

   public void setSCHEMETITLE(final String SCHEMETITLE) {
      this.SCHEMETITLE = SCHEMETITLE;
   }
       
        public void setPERSONIDNO(final String PERSONIDNO){
                this.PERSONIDNO = PERSONIDNO;
        }
}




and my code for main class is:-
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testhibernate;

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

import java.util.*;
/**
*
* @author Administrator
*/
public class TestHibernate {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("Entering main loop");
        Session session = null;
        int qroleId=0;
        int qschemeId=0;
        String trueLogin="S1234567D";
        try{
            System.out.println("Establishing connection");
            // This step will read hibernate.cfg.xml and prepare hibernate for use
            SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
            session =sessionFactory.openSession();
            //Create new instance of Contact and set values in it by reading them from form object
            String SQL_QUERY ="Select ncs_user.PERSONIDNO, ncs_user.ROLEID, ncs_user.SCHEMEID from NCS_User ncs_user where ncs_user.PERSONIDNO="+trueLogin;
            Query query = session.createQuery(SQL_QUERY);
            System.out.println("Query created");

            for(Iterator it=query.iterate();it.hasNext();){
                Object[] row = (Object[]) it.next();
                qroleId = new Integer(row[1].toString());
                System.out.println("Role Id: " + qroleId);
                qschemeId = new Integer(row[2].toString());
                System.out.println("Scheme Id: " + qschemeId);
            }
        }
        catch(Exception e){
            System.out.println(e.getMessage());
        }
        finally{
        // Actual contact insertion will happen at this step
//            session.flush();
//            session.close();
        }
    }
}


I have tried to follow the documentation but I'm getting an error Could not parse mapping document from resource. I was wondering if someone could help me in identifying the reason behind the error.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.