| Author |
invalid colum name GenericJDBCException: could not execute query
|
Emmanuel Garcia
Greenhorn
Joined: Feb 24, 2009
Posts: 12
|
|
I need your help.
This the topic:
I am using JPA with Oracle 9i, JBoss 5.x GA and the default provider is Hibernate.
I am working with "Native Query" and my second test for this was a native query with fields of two entities
This is my query
String sql = "SELECT c.firstName as FIRSTNAME, c.lastname as LASTNAME " +
"FROM CUSTOMER c, CREDITCARD cc " +
"WHERE c.creditcard_id = cc.id";
the two columns selected are from customer table, I had more columns, but I have tested this query because I thought that it will be simplier,
the table CUSTOMER has firstname and lastname columns, and more.
the table CREDITCARD has its columns in form.
When I execute the query as:
Query query = manager.createNativeQuery(sql);
List phones = query.getResultList();
System.out.println("size " + phones.size());
I can see: size 5, the 5 rows in the DB.
And I have not problem if I only get the values as such.
If I make this:
Query query = manager.createNativeQuery(sql,"customerAndCreditCardMapping");
List phones = query.getResultList();
System.out.println("size " + phones.size());
With "customerAndCreditCardMapping" into Customer entity as:
@SqlResultSetMapping(name="customerAndCreditCardMapping",
entities={@EntityResult(entityClass=Customer.class,
fields={@FieldResult(name="firstName", column="FIRSTNAME"),
@FieldResult(name="lastName", column="LASTNAME")}
)})
I get the next exception:
org.hibernate.exception.GenericJDBCException: could not execute query
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:75)
at com.titan.clients.NativeQueries.nativeWithMultipleEntities(NativeQueries.java:75)
at com.titan.clients.NativeQueries.main(NativeQueries.java:28)
Caused by: 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.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:66)
... 2 more
Caused by: java.sql.SQLException: Nombre de columna no vĂ¡lido
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:285)
at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:5278)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:698)
at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1563)
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.loader.Loader.getKeyFromResultSet(Loader.java:1097)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:565)
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)
... 9 more
Exception in thread "main" javax.persistence.RollbackException: Transaction marked as rollbackOnly
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:51)
at com.titan.clients.NativeQueries.main(NativeQueries.java:37)
I ran the SQL from TOAD and it is fine.
The exception is thrown when I try of make the mapping with @SqlResultSetMapping customerAndCreditCardMapping but I don't have idea.
Regards
|
 |
 |
|
|
subject: invalid colum name GenericJDBCException: could not execute query
|
|
|