title: Mapping an java object to a database
body: <p>I am tring to map a java object to database(i am using postgres). when i am runnig the java file (HibernateTest.java) it is showing lot of errors. i think all thing are correct. but i am doubtfull in my eclipse,bcoz it is not supporting xml ( i mean it is not showing color, it is not taking xml file as a know file ). i am a beginner so i cant understand them. plz suggest me.</p>
  
  <p><code>hibernate.cfg.xml</code> file</p>
  
  <pre><code>    &lt;?xml version='1.0' encoding='utf-8'?&gt;
  
      &lt;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"&gt;
        &lt;session-factory&gt;
        &lt;!-- Database connection settings --&gt;
        &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
        &lt;property    name="connection.url"&gt;jdbc:hsqldb:hsql://localhost:5432/hibernatedb&lt;/property&gt;
      &lt;property name="connection.username"&gt;postgres&lt;/property&gt;
      &lt;property name="connection.password"&gt;hkm@1160&lt;/property&gt;
  
      &lt;!-- JDBC connection pool (use the built-in) --&gt;
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
      &lt;!-- SQL dialect --&gt;
      &lt;property name="dialect"&gt;org.hibernate.dialect.PostgreSQlDialect&lt;/property&gt;
  
      &lt;!-- Enable Hibernate's automatic session context management --&gt;
      &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
      &lt;!-- Disable the second-level cache  --&gt;
      &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
  
      &lt;!-- Echo all executed SQL to stdout --&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;!-- Drop and re-create the database schema on startup --&gt;
      &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
      &lt;mapping resource="org.hibernate.hemant.dto.UDestails"/&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><code>UserDetails.java</code>  file</p>
  
  <pre><code>   package org.hibernate.hemant.dto;
     import javax.persistence.Entity;
     import javax.persistence.Id;
  
     @Entity
     public class UserDetails 
     {
     @Id
      private int userID;
      private String userName;
      public int getUserID() {
      return userID;
     }
      public void setUserID(int userID) {
      this.userID = userID;
     }
      public String getUserName() {
      return userName;
     }
      public void setUserName(String userName) {
      this.userName = userName;
     }
   }
  </code></pre>
  
  <p>my main java file <b> HibernateTest.java </b></p>
  
  <pre><code>    package org.hemant.hibernate;
      import org.hibernate.Session;
      import org.hibernate.SessionFactory;
      import org.hibernate.cfg.Configuration;
      import org.hibernate.hemant.dto.UserDetails;
      public class HibernateTest {
  
     /**
     * @param args
     */
      public static void main(String[] args) {
      UserDetails user = new UserDetails();
      user.setUserID(1);
      user.setUserName("First user");
      SessionFactory sessionFactory = new            Configuration().configure().buildSessionFactory();
      Session session = sessionFactory.openSession();
      session.beginTransaction();
      session.save(user);
      session.beginTransaction().commit();
  }
  </code></pre>
  
  <p>}</p>
  
  <p><b>There are the errors......</b></p>
  
  <pre><code>    Apr 13, 2016 9:26:08 PM org.hibernate.Version logVersion
      INFO: HHH000412: Hibernate Core {5.1.0.Final}
      Apr 13, 2016 9:26:08 PM org.hibernate.cfg.Environment &lt;clinit&gt;
      INFO: HHH000206: hibernate.properties not found
      Apr 13, 2016 9:26:08 PM org.hibernate.cfg.Environment buildBytecodeProvider
      INFO: HHH000021: Bytecode provider name : javassistException in thread  "main"
      Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 13 and column 63 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.
  at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:133)
  at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
  at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
  at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)
  at org.hibernate.cfg.Configuration.configure(Configuration.java:259)
  at org.hibernate.cfg.Configuration.configure(Configuration.java:245)
  at org.hemant.hibernate.HibernateTest.main(HibernateTest.java:15)
  Caused by: javax.xml.bind.UnmarshalException
       - with linked exception:
  [org.xml.sax.SAXParseException; lineNumber: 13; columnNumber: 63; cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.]
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(Unknown Source)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown Source)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unknown Source)
  at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:126)
  ... 6 more
      Caused by: org.xml.sax.SAXParseException; lineNumber: 13; columnNumber: 63; cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.
  at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
  at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
  at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
  at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
  at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
  at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
  at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
  at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(Unknown Source)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(Unknown Source)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(Unknown Source)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.handleStartElement(Unknown Source)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.bridge(Unknown Source)
  ... 9 more                
  </code></pre>