Search code examples
javasqlhibernatejdbchibernate-criteria

Hibernate call cast exception


I am having hibernate call to get the data from the table. I am writing the following code :

    List<TABLENAME> list = HibernateSessionFactory.getSession().createCriteria(TABLENAME.class).
    add(Restrictions.isNull("column3")).
    add(Restrictions.eq("column4",groupId)).list();

But while running I m getting CastException

enter image description here

Can anyone pls help to do the fix? I dont know why it needs to cast to integer?

Entity Class :

public class TABLENAME {

    private Timestamp column3;
    private int column4;
Getter and setters of the above variables.
    

}

Solution

  • add(Restrictions.eq("column1",0)).add(Restrictions.eq("Column2",1))
    

    Either your "column1" is of type varchar or your "Column2" is of type varchar.

    Or

    add(Restrictions.eq("column4",groupId)
    

    groupId is not an int...if your column4 is.