无法强制转换为java.io.Serializable [英] Cannot be cast to java.io.Serializable
本文介绍了无法强制转换为java.io.Serializable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用条件来检索用户的详细信息,但在尝试使用正确的用户查询详细信息对象时,我得到了ClassCastException。
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.
我的标准代码;
Criteria criteria = sess.createCriteria(UserDetails.class)
criteria.add(Restrictions.eq("user.id", user.id));
我也尝试过使用;
Criteria criteria = sess.createCriteria(UserDetails.class)
Criteria subCriteria = criteria.createCriteria("user");
subCriteria.add(Restrictions.eq("id", user.id));
两者都给我ClassCastException。我知道我可以通过让用户实现Serializable来轻松解决它,但还有其他解决方案吗?
Both give me the ClassCastException. I know I can easily solve it by letting the User implement Serializable, but is there any other solution?
推荐答案
唯一的其他解决方案是实现Externalizable。
The only other solution is to implement Externalizable.
这篇关于无法强制转换为java.io.Serializable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文