【问题标题】:SQL Error: 17059, SQLState: 99999:org.hibernate.util.JDBCExceptionReporter-[ERROR]: Fail to convert to internal representationSQL 错误:17059,SQLState:99999:org.hibernate.util.JDBCExceptionReporter-[ERROR]:无法转换为内部表示
【发布时间】:2019-11-25 03:04:24
【问题描述】:

调用 API 时从下面的休眠查询中获取异常。

dao类方法:

public List<ErmChangeLog> fetchChangeLog(JsonInput jsonInput) throws SQLException {
    Session session = this.sessionFactory.openSession();    
    List<ErmChangeLog> objectList = null;
    Long instanceKey = 0L;
    try {
        instanceKey = jsonInput.getSystematic_Risk_ID();
        logger.debug("Connection creation process is completed.");
        Query query = session.createQuery(CommonConstants.fetch_ChangeLog);
        logger.info("query   : " + CommonConstants.fetch_ChangeLog);
        query.setParameter("instanceKey", instanceKey);
        logger.info("instanceKey : " + instanceKey);
        objectList = query.list();

    } catch (Exception e) {
        logger.debug("Failed to fetch Change Log");
        e.printStackTrace();
        throw e;
    }
    session.close();
    return objectList;

}

query : String fetch_ChangeLog="from ErmChangeLog p where p.instanceKey =:instanceKey";

例外:

    at java.lang.Thread.run(Thread.java:745)
[2019-07-16 16:39:10,915]:org.hibernate.util.JDBCExceptionReporter-[WARN]: SQL Error: 17059, SQLState: 99999
[2019-07-16 16:39:10,915]:org.hibernate.util.JDBCExceptionReporter-[ERROR]: Fail to convert to internal representation
[2019-07-16 16:39:10,916]:org.hibernate.jdbc.ConnectionManager-[DEBUG]: transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!

【问题讨论】:

    标签: java sql hibernate maven spring-mvc


    【解决方案1】:

    您的参数似乎与查询预期的数据类型不匹配。您可以尝试使用 Integer 而不是 Long 吗?

    【讨论】:

      【解决方案2】:

      我同意@Ucello 的回答;当存在数据类型不匹配时,就会出现这种情况。而且在运行错误的项目版本时也是如此。

      我曾经有分开的前端和后端项目。当我运行 Grails(前端)时,我没有意识到我正在运行 MyApp v3.1 但已经启动了 Java 后端MyApp v3.0。所以,在3.1和3.0版本之间,数据类型不匹配,抛出这个错误。

      不确定这是否有助于其他用户。我花了一些时间才意识到:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-04
        • 2011-08-23
        • 1970-01-01
        • 1970-01-01
        • 2016-07-05
        • 1970-01-01
        相关资源
        最近更新 更多