This is the code :
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Contact.class)
.add(Restrictions.like("gender", "male", MatchMode.ANYWHERE)));
List<Object[]> contactList = criteria.list();
Where gender is enum type column in Contact.java
@Entity
@Table(name = "contact_master")
public class Contact {
public enum Gender {
MALE,FEMALE
}
@Column(name = "gender")
@Enumerated(EnumType.STRING)
private Gender gender;
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
}
When i run above code i am getting exception like :
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Enum