title: Hibernate : java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
body: <p>My Staff Entity defined in Java is like this : </p>
  
  <pre><code>final public class Staff {
      private int staffId;
      private String firstName = null;
      private String lastName = null;
      private String Email = null;
      private double salary;
      //and the setters and getters
  }
  </code></pre>
  
  <p>My Query code : </p>
  
  <pre><code>SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
  Session session = sessionFactory.openSession();
  Staff staff = null;
  try {
      Criteria criteria = session.createCriteria(dto.Staff.class);
      criteria.add(Restrictions.eq("salary", 1000000));
      staff = (Staff) criteria.uniqueResult();
  } catch(Exception e) {
      System.out.println("Error : " + e);
  } finally {
      session.close();
  }
  </code></pre>
  
  <p>But when I run this I get an error which says : </p>
  
  <pre><code>java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
  </code></pre>
  
  <p>If I explicitly cast the number to a double it works :</p>
  
  <pre><code>criteria.add(Restrictions.eq("salary", (double) 1000000));
  </code></pre>
  
  <p>Is there any way to do this without the explicit casting? 
  Also I thought that in Java, Integer to Double conversion was Implicit?</p>