getHibernateTemplate().find()和executeFind()的问题
如下方法:
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);}}
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'第二次查询时出错.错误如下:
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
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;}});}public TaxConfig getTaxConfig(String sys, String key)throws RuntimeException {// TODO Auto-generated method stubObject[] obj = new Object[]{sys,key};/*String hql = "from TaxConfig where sysName='"+sys+"' and key='"+key+"'";System.out.println("hql is ... "+hql);List<TaxConfig> results = getHibernateTemplate().find(hql);*/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);}}<bean id="hibernateTemplate"/></property><property name="cacheQueries"><value>false</value></property></bean>