title: Hibernate does not create Table in the database
body: <p>I am using <code>PostgreSQL</code> and I am trying to run a simple <code>Hibernate</code> application, in particular the application decribed in the <a href="http://viralpatel.net/blogs/hibernate-one-to-many-annotation-tutorial/" rel="nofollow">page</a>. My hibernate.cfg.xml file is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
  
          &lt;property name="hibernate.connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:postgresql:testDB2&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;postgres&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;user&lt;/property&gt;
  
  
          &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
          &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;
          &lt;property name="hibernate.hbm2dll.auto"&gt;create&lt;/property&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
          &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
         &lt;!--  &lt;property name="transaction.factory_class"&gt;org.hibernate.transaction.JDBCTransactionFactory&lt;/property&gt; --&gt;
  
          &lt;mapping class="com.al.hibmaventest.Department"/&gt;
          &lt;mapping class="com.al.hibmaventest.Employee"/&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>My <code>pom.xml</code> (when using maven) is: </p>
  
  <pre><code>   &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.al.hibmaventest&lt;/groupId&gt;
    &lt;artifactId&gt;HibMavenTest&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
    &lt;dependencies&gt;
     &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
              &lt;version&gt;3.2.6.ga&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
        &lt;artifactId&gt;hibernate-annotations&lt;/artifactId&gt;
        &lt;version&gt;3.3.1.GA&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
      &lt;groupId&gt;postgresql&lt;/groupId&gt;
      &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
      &lt;version&gt;9.1-901.jdbc4&lt;/version&gt;
  &lt;/dependency&gt;
    &lt;/dependencies&gt;
  
  
    &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.7&lt;/source&gt;
            &lt;target&gt;1.7&lt;/target&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>I use the <code>main()</code> as it is in the link: </p>
  
  <pre><code>public static void main(String[] args) {
  
          SessionFactory sf = HibernateUtil.getSessionFactory();
          Session session = sf.openSession();
          session.beginTransaction();
  
          Department department = new Department();
          department.setDepartmentName("Sales");
          session.persist(department);
  
          Employee emp1 = new Employee("Nina", "Mayers", "111");
          Employee emp2 = new Employee("Tony", "Almeida", "222");
  
          emp1.setDepartment(department);
          emp2.setDepartment(department);
  
          session.persist(emp1);
          session.persist(emp2);
  
          session.getTransaction().commit();
          session.close();
  
      }
  </code></pre>
  
  <p>However it is impossible to get the application work, namely to do hibernate create the Tables in the Database and insert the value. I receive always, whatever I tried, the same error:</p>
  
  <pre><code>INFO: Not binding factory to JNDI, no JNDI name configured
  Hibernate: insert into Department (DEPT_NAME) values (?)
  Mai 19, 2013 6:56:49 PM org.hibernate.util.JDBCExceptionReporter logExceptions
  WARNING: SQL Error: 0, SQLState: 42P01
  Mai 19, 2013 6:56:49 PM org.hibernate.util.JDBCExceptionReporter logExceptions
  SEVERE: ERROR: relation "department" does not exist
    Position: 13
  Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [com.al.hibmaventest.Department]
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
      at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2163)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2643)
      at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:51)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
      at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
      at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
      at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
      at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
      at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
      at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
      at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
      at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
      at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
      at com.al.hibmaventest.Main.main(Main.java:25)
  Caused by: org.postgresql.util.PSQLException: ERROR: relation "department" does not exist
    Position: 13
      at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
      at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
      at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
      at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:334)
      at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
      at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
      ... 14 more
  </code></pre>
  
  <p>"Relation department does not exist" on line :</p>
  
  <pre><code>session.persist(department); 
  </code></pre>
  
  <p>I have tried it without <code>maven</code> as well, exactly the same error. In order to preempt some readers, the Table (relation) "department" is never created in the database. Even if I create it manually in the Database(what is hibernate expected to do), the error remains the same. I think it is a problem in the creation of the sessions or in the connection withe database. </p>
  
  <p>Does <code>PostgreSQL</code> need configuration to accept <code>Hibernate</code> connection?. Can the problem come from the <code>JNDI</code> as the message says "Not binding factory to JNDI, no JNDI name configured"?</p>
  
  <p>Any suggestions? </p>