TypeMismatchException the provided ID is of a wrong type
I had a different culprit creating this issue: I had copy-pasted another entity's repository which used a String as primary key type.
So I had
class MyEntity implements Serializable {
@Id
Integer id
in combination with
interface MyEntityRepository extends CrudRepository<MyEntity, String> {
which produced the error message.
Simply changing the interface type from String to Integer resolved the issue for me.
It would be easier to answer if you would show how do you retrieve Users. Based to message:
Provided id of the wrong type for class org.cw.form.User.
Expected: class java.lang.Integer, got class java.lang.String
I guess you are providing String instead of correct type (Integer):
String userID = "1"; //Should be Integer userID = 1 instead
session.get(User.class, userID);
public User findClientByUsername(String login) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(User.class);
criteria.add(Restrictions.like("userName", login));
return (User) criteria.uniqueResult();
}
Solution of your problem.