getHibernateTemplate().find()和executeFind()的问题

如下方法:
[code]public TaxConfig getTaxConfig(String sys, String key)throws RuntimeException {
List<TaxConfig> results = find(" from TaxConfig where sysName=? and key=?",obj);

if(results == null || results.isEmpty() ){
throw new RuntimeException("taxConfig not exist!");
}else{
return (TaxConfig)results.get(0);
}

}
[/code]

第一次查询时结果正常,输出的SQL语句也正常.输出的SQL如下:
[code]select taxconfig0_.F_SYSNAME as F1_10_, taxconfig0_.F_KEY as F2_10_, taxconfig0_.F_NOTE as F3_10_, taxconfig0_.F_VALTYPE as F4_10_, taxconfig0_.F_VAL as F5_10_ from tax_config taxconfig0_ where taxconfig0_.F_SYSNAME='sagd' and taxconfig0_.F_KEY='gantPath'[/code]第二次查询时出错.错误如下:
[code]hql is ... from TaxConfig where sysName='sagd' and key='gantPath'
Hibernate: select taxconfig0_.F_SYSNAME as F1_10_0_, taxconfig0_.F_KEY as F2_10_0_, taxconfig0_.F_NOTE as F3_10_0_, taxconfig0_.F_VALTYPE as F4_10_0_, taxconfig0_.F_VAL as F5_10_0_ from tax_config taxconfig0_ where taxconfig0_.F_SYSNAME=?
[sagd] WARN [http-9090-Processor23] DefaultRemoter.warn(67) | Method execution failed:
org.springframework.orm.hibernate3.HibernateSystemException: More than one row with the given identifier was found: sagd, for class: com.lhsm.core.model.TaxConfig; nested exception is org.hibernate.HibernateException: More than one row with the given identifier was found: sagd, for class: com.lhsm.core.model.TaxConfig[/code]
还有就是如果数据库中的表只有一条记录,不会出现上面的问题,多于一条第二次查询就出错.
而换成了如下写法就没有问题,请问这是怎么回事?
[code]public List find(final String hql, final Object... values) {
Assert.hasText(hql);
return super.getHibernateTemplate().executeFind(
new HibernateCallback() {
public Object doInHibernate(Session s)
throws HibernateException, SQLException {
Query query = s.createQuery(hql);
query.setCacheable(false);
for (int i = 0; i < values.length; i++) {
query.setParameter(i, values[i]);
}
List list = query.list();
return list;
}
});
}[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值