我在休眠中使用本机查询,它会返回我的 id 列表。我想将此列表转换为整数列表。但它不起作用并向我显示异常。
public List<Integer> fethcSurvayIdOnCount(){
HibernateCallback action = new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hq = "select id from tb_abc where age='10'" ;
SQLQuery query = (SQLQuery) session
.createSQLQuery(hq)
.setResultTransformer(
Transformers
.aliasToBean(Integer.class));
return query.list();
}
};
return (List<Integer>) getHibernateTemplate()
.execute(action);
}
这是例外
org.springframework.orm.hibernate3.HibernateSystemException: Could not find setter for id on class java.lang.Integer; nested exception is org.hibernate.PropertyNotFoundException: Could not find setter for id on class java.lang.Integer
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:676)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)