我尝试提取jobList
与“用户名”的具体招聘之前抛出异常。所以一切都很顺利,我可以打印招聘人员的用户名,用于通过列表循环获得的工作。但问题是:jobList.add(j)
未被执行,然后直接抛出hibernate异常。有谁知道问题是什么?循环添加记录
我知道我应该使用合适的查询,但我得到异常的时候,我的数据库是非常小的(学校项目),所以它现在并不重要。
public List<Job> list(String userName) throws AdException {
try {
begin();
Query q = getSession().createQuery("FROM Job");
ArrayList<Job> list = (ArrayList<Job>) q.list();
System.out.println("All Jobs: "+ list);
ArrayList<Job> jobList = new ArrayList<Job>();
for (Job j : list) {
System.out.println("job userName is: "+ j.getRecruiter().getUserName());
if (j.getRecruiter().getUserName().equalsIgnoreCase("userName")){
jobList.add(j);
System.out.println("jobList is: "+ jobList);
return jobList;
} else {
continue;
}
}
} catch (HibernateException e) {
rollback();
throw new AdException("Could not get jobList for company: " + userName, e);
}
return null;
}
请发布完整的堆栈跟踪。 –
后异常的完整堆栈跟踪(加上'e.printStackTrace()'来yourcatch条款得到它) –
@JonnyHenly,[在休眠它没有(http://www.tutorialspoint.com/hibernate/ hibernate_query_language.htm) – Draken