Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

jpql - java.sql.SQLException: Fail to convert to internal representation

I'm trying execute following query:

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

And take exception:

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

question from:https://stackoverflow.com/questions/5963472/java-sql-sqlexception-fail-to-convert-to-internal-representation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...