TbDiscussionForumAnswere

TbDiscussionForumAnswere

我只想检索数据列表,但是通过使用下面的代码为什么我得到类强制转换异常...

public List<TbDiscussionForumAnswere> findTbDiscussionForumAnswerebyforumQuestionId(Integer forumQuestionId) {
session = sessionFactory.getCurrentSession();
TbDiscussionForumAnswere TbDiscussionForumAnswere = (TbDiscussionForumAnswere)session.createCriteria(TbDiscussionForumAnswere.class)                .add(Restrictions.eq("forumQuestionId.forumQuestionId", forumQuestionId));
return (List<TbDiscussionForumAnswere>) TbDiscussionForumAnswere.getTbDiscussionForumAnswereCollection();
}


上面的方法给我下面的异常

java.lang.ClassCastException: org.hibernate.internal.CriteriaImpl cannot be cast to com.medikm.entity.TbDiscussionForumAnswere


感谢你

最佳答案

您正在创建Criteria对象而不是TbDiscussionForumAnswere对象。这是正确的错误信息。
您使用此Criteria类执行查询。您应该将其转换为Criteria

10-07 16:09