Cannot be cast to java.io.Serializable

Thizzer picture Thizzer · Dec 24, 2010 · Viewed 44.1k times · Source

I am currently using criteria to retrieve the details of a user, but when trying to query the details object with the right user, I get a ClassCastException.

My Criteria Code;

Criteria criteria = sess.createCriteria(UserDetails.class)
criteria.add(Restrictions.eq("user.id", user.id));

I also tried using;

Criteria criteria = sess.createCriteria(UserDetails.class)

Criteria subCriteria = criteria.createCriteria("user");
subCriteria.add(Restrictions.eq("id", user.id));

Both give me the ClassCastException. I know I can easily solve it by letting the User implement Serializable, but is there any other solution?

Answer

user467871 picture user467871 · Dec 24, 2010

You should implement Serializable interface.