简体   繁体   English

substr错误:org.hibernate.exception.GenericJDBCException:无法执行查询

[英]substr error: org.hibernate.exception.GenericJDBCException: could not execute query

I am trying SUBSTR for a query in Hibernate using the Criteria API: 我正在尝试使用Criteria API在Hibernate中对SUBSTR进行查询:

        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();

But i am getting the exception: 但我得到了例外:

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

The SQL query getting printed in the console is: 在控制台中打印的SQL查询为:

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

When i execute this in my DB then it is working fine. 当我在数据库中执行此操作时,它工作正常。

Please let me know the reason for this exception. 请让我知道此例外的原因。

Regards, 问候,

异常的Caused by: java.sql.SQLException: Fail to convert to internal representation表示在处理字段值时数据类型不匹配(例如,将char分配给int)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ested异常是org.hibernate.exception.GenericJDBCException:无法执行查询 - ested exception is org.hibernate.exception.GenericJDBCException: could not execute query org.hibernate.exception.GenericJDBCException:无法执行查询]的根本原因 - org.hibernate.exception.GenericJDBCException: could not execute query] with root cause org.hibernate.exception.GenericJDBCException:无法执行查询 - org.hibernate.exception.GenericJDBCException: could not execute query org.hibernate.exception.GenericJDBCException:无法执行查询 - org.hibernate.exception.GenericJDBCException: could not execute query org.hibernate.exception.GenericJDBCException:无法在hibernate中执行语句 - org.hibernate.exception.GenericJDBCException: could not execute statement in hibernate 错误信息:无法执行语句; 嵌套异常是 org.hibernate.exception.GenericJDBCException:无法执行语句 - Error message: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement org.hibernate.exception.GenericJDBCException:无法执行语句 - org.hibernate.exception.GenericJDBCException: could not execute statement 更新查询的 JPA @Query 注释(oracle sql 开发人员)--org.hibernate.exception.GenericJDBCException:无法执行查询 - JPA @Query annotation for update query (oracle sql developer) -- org.hibernate.exception.GenericJDBCException: could not execute query org.hibernate.exception.GenericJDBCException:执行此代码时无法执行查询异常 - org.hibernate.exception.GenericJDBCException: could not execute query Exception while executing this code org.hibernate.exception.GenericJDBCException:无法插入: - org.hibernate.exception.GenericJDBCException: could not insert:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM