hibernate 遇到Source not found for 错误

29 篇文章 0 订阅
26 篇文章 0 订阅

以下代码运行时有个没有任何错误提示,但无法取得结果

@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
这类信息时,要把真正的错误抛出来,才能对症解决你的问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值