[英]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.