java.sql.SQLException:无法转换为内部表示形式 [英] java.sql.SQLException: Fail to convert to internal representation

查看:465
本文介绍了java.sql.SQLException:无法转换为内部表示形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下查询:

I'm trying execute following query:

String query = "select entity, entity.id from Site entity";
List resultList = entityManager.createQuery(query).getResultList();

并采取例外措施:

[...]
Caused by: java.sql.SQLException: Fail to convert to internal representation
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
    at oracle.jdbc.driver.CharCommonAccessor.getLong(CharCommonAccessor.java:239)
    at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:552)
    at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1575)
    at org.jboss.resource.adapter.jdbc.WrappedResultSet.getLong(WrappedResultSet.java:724)
    at org.hibernate.type.LongType.get(LongType.java:28)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
    at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:103)
    at org.hibernate.type.EntityType.nullSafeGet(EntityType.java:204)
    at org.hibernate.loader.hql.QueryLoader.getResultColumnOrRow(QueryLoader.java:338)
    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)
    ... 102 more

我做错了什么? 预先谢谢你.

What am I doing wrong? Thank you in advance.

推荐答案

检索字段值时,您的数据类型不匹配.检查您的代码,并确保对于要检索的每个字段,java对象均与该类型匹配.例如,将日期检索到int和int中.如果您要进行选择*,则表中字段的更改可能已发生,从而导致此错误的发生.您的SQL应该只选择您特别想要的字段,以免发生此错误.

Your data types are mismatched when you are retrieving the field values. Check your code and ensure that for each field that you are retrieving that the java object matches that type. For example, retrieving a date into and int. If you are doing a select * then it is possible a change in the fields of the table has happened causing this error to occur. Your SQL should only select the fields you specifically want in order to avoid this error.

希望这会有所帮助.

这篇关于java.sql.SQLException:无法转换为内部表示形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆