title: How to connect postgresql in hibernate.cfg.xml
body: <p>I am trying to insert some data into postgresql through hibernate. However, there are not much tutorial about configurate hibernate with postgresql (I know, it should be similar to mysql =)) </p>
  
  <p>src/main/resources/hibernate.cfg.xml</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
  &lt;session-factory&gt;
  &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
  &lt;property name="connection.url"&gt;jdbc:postgresql://127.0.0.1:5432/myDatabase&lt;/property&gt;
  &lt;property name="connection.username"&gt;myUser&lt;/property&gt;
  &lt;property name="connection.password"&gt;myPassword&lt;/property&gt;
  
  &lt;!-- JDBC connection pool (use the build-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;property name="cache.provider_class"&gt;org.hibernate.cache.HashtableCacheProvider&lt;/property&gt;
  &lt;property name="transaction.factory_class"&gt;org.hibernate.transaction.JDBCTransactionFactory&lt;/property&gt;
  
  &lt;!-- thread is the short name for org.hibernate.context.ThreadLocalSessionContext --&gt;
  &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
  &lt;!-- Set "true" to show SQL statements --&gt;
  &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;
  
  &lt;!-- mapping class using annotation --&gt;
  &lt;mapping class="com.hib.entities.Student"&gt;&lt;/mapping&gt;
  &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>src/main/java/</p>
  
  <pre><code>package com.hib.init;
  
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  import org.hibernate.service.ServiceRegistryBuilder;
  
  public class Hibernateutil {
  private static final SessionFactory sessionF;
  private static final ServiceRegistry serviceR;
  
  static {
      Configuration conf = new Configuration();
      conf.configure();
      System.out.println("Begin");
      serviceR = new ServiceRegistryBuilder().applySettings(conf.getProperties()).buildServiceRegistry();
      System.out.println("Ready???");
      try {
          sessionF = conf.buildSessionFactory(serviceR);
          System.out.println("Success??");
      }catch(Exception e) {
          throw new ExceptionInInitializerError(e);
      }
  }
  
  public static SessionFactory getSeeionFactory() {
      return sessionF;
  }
  }
  </code></pre>
  
  <p>src/main/java
      package com.hib.entities;</p>
  
  <pre><code>import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table
  public class Student {
  
  @Id
  @GeneratedValue
  private Integer id;
  private String firstName;
  
  private Integer age;
  
  public Student() {}
  
  public Student(Integer id, String firstName, Integer age) {
      super();
      this.id = id;
      this.firstName = firstName;
      this.age = age;
  }
  
  public Integer getId() {
      return id;
  }
  
  public void setId(Integer id) {
      this.id = id;
  }
  
  public String getFirstName() {
      return firstName;
  }
  
  public void setFirstName(String firstName) {
      this.firstName = firstName;
  }
  
  public Integer getAge() {
      return age;
  }
  
  public void setAge(Integer age) {
      this.age = age;
  }   
  }
  </code></pre>
  
  <p>src/main/java</p>
  
  <pre><code>package com.hib.demo;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import com.hib.entities.Student;
  import com.hib.init.Hibernateutil;
  
  public class DemoFirst {
  
  public static void main(String[] args) {
      SessionFactory sessionFactory = Hibernateutil.getSeeionFactory();
      Session session = sessionFactory.openSession();
      session.beginTransaction();
  
      Student student = new Student();
      student.setFirstName("Bob");
      student.setAge(26);
  
      session.save(student);
      session.getTransaction().commit();
  
      session.close();
  }
  }
  </code></pre>
  
  <p>And this is the error I got :</p>
  
  <pre><code>Success??
  Hibernate: select nextval ('hibernate_sequence')
  Aug 12, 2014 11:01:10 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  WARN: SQL Error: 0, SQLState: 42P01
  Aug 12, 2014 11:01:10 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  ERROR: ERROR: relation "hibernate_sequence" does not exist
  Position: 17
  Exception in thread "main" org.hibernate.exception.SQLGrammarException: ERROR: relation        "hibernate_sequence" does not exist
  Position: 17
  at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
  at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
  at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
  at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
  at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
  at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
  at com.sun.proxy.$Proxy9.executeQuery(Unknown Source)
  at org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:123)
  at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:116)
  at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:120)
  at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
  at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
  at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
  at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
  at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
  at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:642)
  at org.hibernate.internal.SessionImpl.save(SessionImpl.java:635)
  at org.hibernate.internal.SessionImpl.save(SessionImpl.java:631)
  at com.hib.demo.DemoFirst.main(DemoFirst.java:20)
  
  
  Caused by: org.postgresql.util.PSQLException: ERROR: relation "hibernate_sequence" does not exist
  Position: 17
  at    org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
  at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
  at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
  at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
  at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
  at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
  ... 14 more
  </code></pre>
  
  <p>pom.xml</p>
  
  <pre><code> &lt;dependency&gt;
      &lt;groupId&gt;postgresql&lt;/groupId&gt;
      &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
      &lt;version&gt;8.4-701.jdbc4&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>