日期:2014-05-20  浏览次数:20662 次

求助 SSH开发
这是topic的实体类字段

  private Long tid;
private String tcontent;
private String thard;
private String tdate;
private String tremark;
private String tstate;
private String tpoint;

private QuesType quesType;
private Answer aw;
private Exam exam;

首先是basedaoimpl类里面的getList方法
public List<T> getList(String hql, Object[] params, int pageSize,int pageNum) {
Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
Query query = session.createQuery(hql);
if (params != null) {
for (int i = 0; i < params.length; i++) {
query.setParameter(i, params[i]);
}
}
query.setFirstResult(pageSize*(pageNum-1)).setMaxResults(pageSize);
return query.list();
}

然后是daoimpl里的方法 继承basedaoimpl
public List<Topic> getTopics(int eid, int qid, int pageSize,int pageNum ) {
String hql="from Topic where exam.eid like ? and quesType.qid like ?";
List<Topic> topics=getList(hql, new Integer[]{eid,qid}, pageSize, pageNum);
return topics;
}

再是bizimpl
public List<Topic> getTopics(int eid, int qid, int pageSize, int pageNum) {
return topicDAO.getTopics(eid, qid, pageSize, pageNum);
}
再是action里的方法
public String getTopics(){
List<Topic> topicsList=topicBiz.getTopics(topic.getExam().getEid(), topic.getQuesType(). getQid(), pageSize, pageNum);
int totalCount=topicBiz.getTopicCount(topic.getExam().getEid(), topic.getQuesType().getQid());
totalPage=PageUtil.getPageTotal(totalCount, pageSize);
HibernateSessionUtil.setAttribute("topicsList", topicsList);
HibernateSessionUtil.setAttribute("totalCount", totalCount);
HibernateSessionUtil.setAttribute("pageSize", pageSize);
HibernateSessionUtil.setAttribute("totalPage", totalPage);
return "topics";
}

我用断点测试的时候 发现一直到daoimpl中return的topics的值 都是对的 但是到了bizimpl的时候 有这么一句话Source not found for $Proxy10.getTopics(int, int, int, int) line: not available 继续到action里面 
得出的 topicList值也是对的 但是继续下去就报错了  
错误如下:
org.springframework.orm.hibernate3.HibernateQueryException: Expected positional parameter count: 2, actual parameters: [] [from Topic where exam.eid like ? and quesType.qid like ? ]; nested exception is org.hibernate.QueryException: Expected positional parameter count: 2, actual parameters: [] [from Topic where exam.eid like ? and quesType.qid like ? ]
这是页面包的错误 不是tomcat报的错 好像是说占位符的问题 我想知道 我是不是basedaoimpl里面的getlist方法写的不对 还是什么 求各位帮忙看下 谢谢了 本人菜鸟 刚学不久 


------解决方案--------------------
好像是HQL语句的参数个数与你执行查询时传入的参数不匹配,
把异常信息贴全了,你的debug描述不太清楚
------解决方案--------------------
你测试的时候,给那几个参数赋值了吗。。。没赋值自然是not available 了。。。
------解决方案--------------------
for (int i = 0; i < params.length; i++)
估计就是这一块的问题了。。。 
你改成for (int i = 1; i <= params.length; i++)试试