title: org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist - Hibernate
body: <p>I have a model class that is mapped to a postgres database using hibernate. My model class is:</p>
  
  <pre><code>@Entity
  @Table(name="USER")
  public class User {
  
      @Id 
      @GeneratedValue
      @Column(name="id")
      private long id;
  
      @Column(name="username", unique=true)
      private String username;
  
      @Column(name="email")
      private String email;
  
      @Column(name="created")
      private Timestamp created;
  
      public User(long id, String username, String email) {
          this.id = id;
          this.username = username;
          this.email = email;
      }
  }
  </code></pre>
  
  <p>I try to retrieve the user with username "adam" using the below query:</p>
  
  <pre><code>tx = session.beginTransaction();
  TypedQuery&lt;User&gt; query = session.createQuery("FROM User u WHERE u.username = :username", User.class).setParameter("username", "adam");
  user = query.getSingleResult();
  </code></pre>
  
  <p>I get an exception that says:</p>
  
  <pre><code>org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist
  </code></pre>
  
  <p>My database from bash shell looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/02Deb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/02Deb.png" alt="database"></a></p>
  
  <p>How does hibernate map class attributes to table columns? Does it match based on the <code>@Column(name="username")</code> only or does it also try to match based on datatypes and constraints such as unique/auto-increment?</p>