以下代码运行时有个没有任何错误提示,但无法取得结果
@Service
public class KCardService extends HibernateEntityHwattDao<KCard>{
@SuppressWarnings("unchecked")
public List<KCard> getCardsByEmployee(KEmployee employee,Date start,Date end){
String hql = "from KCard where c.employeeId=? and c.cardTime>=? and c.cardTime<=? order by c.cardTime;";
List<KCard> dataList = find(hql, employee.getEmployeeId(),start,end);
return dataList;
}
}
debug 追踪到运行find方法时会出错并直接跳过。错误为
Source not found for KCardService$$FastClassByCGLIB$$431f75e2.invoke(int, Object, Object[]) line: not available
根据网上的查询,众说纷纭。但得到一个好的解决方法,就是try catch整个方法,抛出错误。
@Service
public class KCardService extends HibernateEntityHwattDao<KCard>{
@SuppressWarnings("unchecked")
public List<KCard> getCardsByEmployee(KEmployee employee,Date start,Date end){
try {
String hql = "from KCard where c.employeeId=? and c.cardTime>=? and c.cardTime<=? order by c.cardTime;";
List<KCard> dataList = find(hql, employee.getEmployeeId(),start,end);
return dataList;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
错误输出
org.hibernate.QueryException: unexpected char: ';' [from com.hbzy.modelhwatt.KCard where c.employeeId=? and c.cardTime>=? and c.cardTime<=? order by c.cardTime;]
分析错误知道是多了";"
去掉再运行
org.hibernate.QueryException: Unable to resolve path [c.employeeId], unexpected token [c] [from com.hbzy.modelhwatt.KCard where c.employeeId=? and c.cardTime>=? and c.cardTime<=? order by c.cardTime]
分析错误知道是少了 实体类简拼 c 定义
最后修改完后测试没问题了,便吧try catch去掉了,最后代码改为
@Service
public class KCardService extends HibernateEntityHwattDao<KCard>{
@SuppressWarnings("unchecked")
public List<KCard> getCardsByEmployee(KEmployee employee,Date start,Date end){
String hql = "from KCard c where c.employeeId=? and c.cardTime>=? and c.cardTime<=? order by c.cardTime";
List<KCard> dataList = find(hql, employee.getEmployeeId(),start,end);
return dataList;
}
}
通过以上过程发现,hibernate没有把错误抛出来,当出现
Source not found for KCardService$$FastClassByCGLIB$$431f75e2.invoke(int, Object, Object[]) line: not available
这类信息时,要把真正的错误抛出来,才能对症解决你的问题。