2013-01-05 104 views
1

我使用的是標準API試圖SUBSTR對Hibernate的查詢:SUBSTR錯誤:org.hibernate.exception.GenericJDBCException:無法執行查詢

 Type[] type = {Hibernate.INTEGER,Hibernate.INTEGER}; 
     Criteria criteria = session.createCriteria(Dept.class).setProjection(Projections.projectionList().add(Projections.sqlProjection("substr(DEPT_NAME,1,3) as name", new String[]{"name"}, type)));   
     List<String> list1 = criteria.list(); 

但我得到異常:

org.hibernate.exception.GenericJDBCException: could not execute query 
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103) 
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91) 
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) 
at org.hibernate.loader.Loader.doList(Loader.java:2223) 
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) 
at org.hibernate.loader.Loader.list(Loader.java:2099) 
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94) 
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569) 
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283) 
at com.infy.jdbc.HibernateStartup.main(HibernateStartup.java:196) 
Caused by: java.sql.SQLException: Fail to convert to internal representation 
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111) 
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145) 
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207) 
at oracle.jdbc.driver.CharCommonAccessor.getInt(CharCommonAccessor.java:131) 
at oracle.jdbc.driver.OracleResultSetImpl.getInt(OracleResultSetImpl.java:520) 
at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1562) 
at org.hibernate.type.IntegerType.get(IntegerType.java:28) 
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163) 
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189) 
at org.hibernate.loader.criteria.CriteriaLoader.getResultColumnOrRow(CriteriaLoader.java:107) 
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606) 
at org.hibernate.loader.Loader.doQuery(Loader.java:701) 
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) 
at org.hibernate.loader.Loader.doList(Loader.java:2220) 
... 6 more 

SQL查詢得到印刷在控制檯是:

Hibernate: select substr(DEPT_NAME,1,3) as name from dept this_

當我在我的數據庫中執行此操作時,它工作正常。

請讓我知道這個例外的原因。

問候,

回答

0

例外Caused by: java.sql.SQLException: Fail to convert to internal representation 說,有一個不匹配的數據類型,同時與字段值處理(例如,指派字符爲int)。

相關問題