title: PSQLException: ERROR: relation "TABLE_NAME" does not exist
body: <p>I am trying to run hibernate on a PostgreSQL 8.4.2 DB. Whenever I try to run a simple java code like: </p>
  
  <pre><code>List&lt;User&gt; users = service.findAllUsers();
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>PSQLException: ERROR: relation "TABLE_NAME" does not exist
  </code></pre>
  
  <p>Since I have option hibernate.show_sql option set to true, I can see that hibernate is trying to run the following SQL command:</p>
  
  <pre><code>    select this_.USERNAME as USERNAME0_0_, this_.PASSWORD as PASSWORD0_0_ 
  from "TABLE_NAME" this_
  </code></pre>
  
  <p>When in reality, it should at least run something like:</p>
  
  <pre><code>    select this_."USERNAME" as USERNAME0_0_, this_."PASSWORD" as PASSWORD0_0_ 
  from "SCHEMA_NAME"."TABLE_NAME" as this_
  </code></pre>
  
  <p>Does anyone know what changes I need to make for Hibernate to produce the right SQL for PostgreSQL?</p>
  
  <p>I have set up the necessary postgreSQL datasource in applicationContext.xml file:</p>
  
  <pre><code>&lt;!-- Use Spring annotations --&gt;
   &lt;context:annotation-config /&gt; 
   &lt;!-- postgreSQL datasource --&gt;
   &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close"&gt;
    &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
    &lt;property name="url"
     value="jdbc:postgresql://localhost/DB_NAME:5432/SCHEMA_NAME" /&gt;
    &lt;property name="username" value="postgres" /&gt;
    &lt;property name="password" value="password" /&gt;
    &lt;property name="defaultAutoCommit" value="false" /&gt;
   &lt;/bean&gt;
  </code></pre>
  
  <p>On the same file I have set up the session factory with PostgreSQL dialect:</p>
  
  <pre><code>&lt;!-- Hibernate session factory --&gt;
   &lt;bean id="sessionFactory"   class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
    &lt;property name="annotatedClasses"&gt;
     &lt;list&gt;
      &lt;value&gt;com.myPackage.dbEntities.domain.User&lt;/value&gt;
     &lt;/list&gt;
    &lt;/property&gt;
    &lt;property name="hibernateProperties"&gt;
     &lt;props&gt;
      &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/prop&gt;
      &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
     &lt;/props&gt;
    &lt;/property&gt;
   &lt;/bean&gt;
   &lt;!-- setup transaction manager --&gt;
   &lt;bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
    &lt;property name="sessionFactory"&gt;
     &lt;ref bean="sessionFactory" /&gt;
    &lt;/property&gt;
   &lt;/bean&gt;
  </code></pre>
  
  <p>Finally, the way I am mapping the domain class to the table is:</p>
  
  <pre><code>    @Entity
  @Table(name = "`TABLE_NAME`")
  public class User {
  @Id
  @Column(name = "USERNAME")
  private String username;
  </code></pre>
  
  <p>Has anyone encountered a similar error?. Any help in solving this issue will be much appreciated. 
  Please note that question is different to post <a href="https://stackoverflow.com/questions/695289/cannot-simply-use-postgresql-table-name-relation-does-not-exist">Cannot simply use PostgreSQL table name (”relation does not exist”)</a></p>
  
  <p>Apologies for the lengthy post.</p>