我试图使用hibernate读取特定的列数据。
这是我的SQL查询
select current_state,count(current_state) from cssaction group by current_state
当我在工作台编辑器
中执行时,它运行良好输出:
当我在休眠时通过Session执行相同的查询时,我得到了异常。
代码:
List<Object[]> resultList = getSessionFactory().getCurrentSession().
createQuery("select currentState,count(currentState) from CssAction group by currentState").getResultList();
例外:
May 18, 2017 4:19:52 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: null
May 18, 2017 4:19:52 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: An SQLException was provoked by the following failure: java.lang.NumberFormatException: For input string: "CLOSED"
May 18, 2017 4:19:52 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/Test] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query] with root cause
java.lang.NumberFormatException: For input string: "CLOSED"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at com.mysql.cj.core.io.MysqlTextValueDecoder.decodeDouble(MysqlTextValueDecoder.java:222)
at com.mysql.cj.core.io.StringConverter.createFromBytes(StringConverter.java:104)
at com.mysql.cj.core.io.MysqlTextValueDecoder.decodeByteArray(MysqlTextValueDecoder.java:232)
at com.mysql.cj.mysqla.result.AbstractResultsetRow.decodeAndCreateReturnValue(AbstractResultsetRow.java:124)
at com.mysql.cj.mysqla.result.AbstractResultsetRow.getValueFromBytes(AbstractResultsetRow.java:225)
at com.mysql.cj.mysqla.result.ByteArrayRow.getValue(ByteArrayRow.java:84)
at com.mysql.cj.jdbc.result.ResultSetImpl.getNonStringValueFromRow(ResultSetImpl.java:630)
at com.mysql.cj.jdbc.result.ResultSetImpl.getInt(ResultSetImpl.java:829)
at com.mysql.cj.jdbc.result.ResultSetImpl.getInt(ResultSetImpl.java:847)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getInt(NewProxyResultSet.java:2677)
at org.hibernate.type.EnumType$OrdinalEnumValueMapper.getValue(EnumType.java:337)
at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:231)
at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:119)
at org.hibernate.loader.hql.QueryLoader.getResultRow(QueryLoader.java:453)
at org.hibernate.loader.hql.QueryLoader.getResultColumnOrRow(QueryLoader.java:436)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:769)
at org.hibernate.loader.Loader.processResultSet(Loader.java:985)
at org.hibernate.loader.Loader.doQuery(Loader.java:943)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349)
at org.hibernate.loader.Loader.doList(Loader.java:2615)
at org.hibernate.loader.Loader.doList(Loader.java:2598)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2430)
at org.hibernate.loader.Loader.list(Loader.java:2425)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:375)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1481)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1441)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1410)
at org.hibernate.query.Query.getResultList(Query.java:146)