title: How to connect hibernate with PostgreSQL in eclipse?
body: <p>I try to connect hibernate with PostgreSQL, but I don't know why it is not working.
  I have searched many posts about the setting, but they are not working for me.
  Thank you very much!</p>
  
  <p><strong>Below is the structure of my files:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/jbhaQ.png" alt="enter image description here"></p>
  
  <p><strong>hibernate.cfg.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration SYSTEM 
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
     &lt;session-factory&gt;
     &lt;property name="hibernate.dialect"&gt;
        org.hibernate.dialect.PostgreSQLDialect
     &lt;/property&gt;
     &lt;property name="hibernate.connection.driver_class"&gt;
        org.postgresql.Driver
     &lt;/property&gt;
     &lt;property name="hibernate.connection.url"&gt;
        jdbc:postgresql://localhost:5432/hibernatedb
     &lt;/property&gt;
     &lt;property name="hibernate.connection.username"&gt;
        eric
     &lt;/property&gt;
     &lt;property name="hibernate.connection.password"&gt;
        eric123
     &lt;/property&gt;
  
     &lt;mapping resource="Employee.hbm.xml"/&gt;
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><strong>Employee.hbm.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC 
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt; 
  
  &lt;hibernate-mapping&gt;
     &lt;class name="Employee" table="EMPLOYEE"&gt;
        &lt;meta attribute="class-description"&gt;
           This class contains the employee detail. 
        &lt;/meta&gt;
        &lt;id name="id" type="int" column="id"&gt;
           &lt;generator class="native"/&gt;
        &lt;/id&gt;
        &lt;property name="firstName" column="first_name" type="string"/&gt;
        &lt;property name="lastName" column="last_name" type="string"/&gt;
        &lt;property name="salary" column="salary" type="int"/&gt;
     &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p><strong>Employee.java</strong></p>
  
  <pre><code>package hibernate.application;
  
      public class Employee {
         private int id;
         private String firstName; 
         private String lastName;   
         private int salary;  
  
         public Employee() {}
         public Employee(String fname, String lname, int salary) {
            this.firstName = fname;
            this.lastName = lname;
            this.salary = salary;
         }
         public int getId() {
            return id;
         }
         public void setId( int id ) {
            this.id = id;
         }
         public String getFirstName() {
            return firstName;
         }
         public void setFirstName( String first_name ) {
            this.firstName = first_name;
         }
         public String getLastName() {
            return lastName;
         }
         public void setLastName( String last_name ) {
            this.lastName = last_name;
         }
         public int getSalary() {
            return salary;
         }
         public void setSalary( int salary ) {
            this.salary = salary;
         }
      }
  </code></pre>
  
  <p><strong>ManageEmployee.java</strong></p>
  
  <pre><code>public class ManageEmployee {
     private static SessionFactory factory;
     private static ServiceRegistry serviceRegistry;
  
     public static void main(String[] args) {
          Configuration configuration = new Configuration();
          configuration.configure();
          serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();        
          factory = configuration.buildSessionFactory(serviceRegistry);   
  
          ManageEmployee ME = new ManageEmployee();
          Integer empID1 = ME.addEmployee("Zara", "Ali", 1000);
          ...
     }   
  }
  </code></pre>
  
  <p><strong>Error Messages</strong></p>
  
  <pre><code>2013/9/26 上午 10:40:56 org.hibernate.annotations.common.Version &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
  2013/9/26 上午 10:40:56 org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {4.2.5.Final}
  2013/9/26 上午 10:40:56 org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  2013/9/26 上午 10:40:56 org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  2013/9/26 上午 10:40:56 org.hibernate.cfg.Configuration configure
  INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
  2013/9/26 上午 10:40:56 org.hibernate.cfg.Configuration getConfigurationInputStream
  INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
  2013/9/26 上午 10:40:56 org.hibernate.cfg.Configuration addResource
  INFO: HHH000221: Reading mappings from resource: Employee.hbm.xml
  2013/9/26 上午 10:40:56 org.hibernate.cfg.Configuration doConfigure
  INFO: HHH000041: Configured SessionFactory: null
  2013/9/26 上午 10:40:56 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
  Exception in thread "main" org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver org.postgresql.Driver could not be loaded
      at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:111)
      at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
      at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
      at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1818)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1776)
      at hibernate.application.ManageEmployee.main(ManageEmployee.java:18)
  Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.postgresql.Driver]
      at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:149)
      at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
      ... 11 more
  Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver
      at java.lang.Class.forName(Class.java:172)
      at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:146)
      ... 12 more
  </code></pre>