Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jpql

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.

like image 540
Ket Avatar asked May 11 '11 11:05

Ket


2 Answers

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.

like image 158
Ashish Avatar answered Sep 21 '22 00:09

Ashish


Check your Entity class. Use String instead of Long and float instead of double .

like image 40
BlackKat Avatar answered Sep 24 '22 00:09

BlackKat