title: Criteria Query using Postgres
body: <p>Using :-
      Postgres : PostgreSQL 10.0
      Hibernate      : 4.0.1</p>
  
  <p>I have the following example table created in Postgres</p>
  
  <pre><code>CREATE TABLE Automobile
  (id                          SERIAL               
  ,name                        VARCHAR(20)        
  ,year                        INTEGER        
  );
  </code></pre>
  
  <p>I have created a domain Automobile class.</p>
  
  <p>I have the following hibernate criteria query to return all the names for a particular year.</p>
  
  <pre><code>    final Criteria criteria = session.createCriteria (Automobile.class);
  
      criteria.add (Restrictions.eq ("year", 1 ));
  
      List&lt;Automobile&gt; list = criteria.list();
  </code></pre>
  
  <p>However, the list() is generating the following exception.</p>
  
  <pre><code>    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
  </code></pre>
  
  <p>So I changed query to pass in a String value for the "year" :-</p>
  
  <pre><code>    criteria.add (Restrictions.eq ("year", new String("1")));
  
      List&lt;Automobile&gt; list = criteria.list();
  </code></pre>
  
  <p>However, the list() is generating a different exception.</p>
  
  <pre><code>    org.hibernate.exception.SQLGrammarException: ERROR: operator does not exist: integer = character varying
      Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
      Position: 1145
  </code></pre>
  
  <p>Any thoughts on what maybe the cause and solution that would return me list of matches please ?</p>
  
  <p>Thank you 
  Pete.</p>