hibernate中用max查询出错
我的代码:
String queryString = "select max(zkz) from table1 where zkz like '0101% ' ";
Object obj = session.createQuery(queryString).uniqueResult();
return (Integer)obj;
提示出错:
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.AggregateNode
\-[AGGREGATE] AggregateNode: 'max '
\-[IDENT] IdentNode: 'zkz ' {originalText=zkz}
[解决办法]
hibernate是一种O\R映射。所以说在查的时候必须是”持久化类“
String queryString = "select max(zkz) from table1(错误) where zkz like '0101% ' ";
Object obj = session.createQuery(queryString).uniqueResult();
return (Integer)obj;