日期:2014-05-16  浏览次数:20496 次

hibernateTemplate.findByNamedParam 查询无数据问题
这两天出现了一个这样的问题:
使用hibernateTemplate.findByNamedParam("HQL",new Object[]{})查询的时候,发现竟然有查不到数据的问题, 其他的查询也是使用这种方式 ,为什么这个方法就查不到呢? 也没有报错, 就是返回一个大小为0的List ,为什么?  经过debug跟踪,到了hiberante内部一步一步, 发现不管是最后的Sql语句、参数都没有问题,但是就查不到。
后来猛的惊醒是数据里面的数据完整吗?  后来发现果然多了一个换行空格!

public List<CollegeMajors> queryByCollegesId(CollegeMajors e)
			throws Exception {
		List<CollegeMajors> collegeMajorsList = null;
		collegeMajorsList = this.hibernateTemplate
				.findByNamedParam(
						"from CollegeMajors as collegeMajors where collegeMajors.collegesId=:collegesId",
						"collegesId", e.getCollegesId());
		if (collegeMajorsList == null) {
			collegeMajorsList = new ArrayList<CollegeMajors>();
		}
		return collegeMajorsList;
	}