gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 04:55:49 24 4
gpt4 key购买 nike

我正在尝试使用 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();

但我遇到了异常(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

在控制台中打印的 SQL 查询是:

Hibernate:选择 substr(DEPT_NAME,1,3) 作为部门 this_ 的名称

当我在数据库中执行此操作时,它工作正常。

请让我知道此异常的原因。

问候,

最佳答案

异常引起:java.sql.SQLException:无法转换为内部表示
表示处理字段值时数据类型不匹配(例如,将 char 分配给 int)。

关于java - substr错误: org. hibernate.exception.GenericJDBCException:无法执行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14168989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com