Hibernate version: 3.0.5
Mapping documents:
Code:
<class name="ResourcePersistence" table="shark_resource">
<id column="objectId" type="long">
<generator class="sequence">
<param name="sequence">shark_sequence</param>
</generator>
</id>
<property name="deleted" />
<property name="name"/>
<property name="username" not-null="true" unique="true"/>
</class>
Code between sessionFactory.openSession() and session.close():query="select * from shark_resource where deleted = 0 ;"
SQLQuery q =session.createSQLQuery(query);
q.addEntity("a",ResourcePersistence.class);
Full stack trace of any exception that occurs:Code:
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1596)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1414)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)
at be.rmi.shark.hibernate.persistence.PersistenceManager.nativeList(PersistenceManager.java:189)
... 41 more
Caused by: java.sql.SQLException: Nom de colonne non valide
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.OracleStatement.getColumnIndex(OracleStatement.java:3295)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1914)
at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1575)
at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getLong(DelegatingResultSet.java:239)
at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getLong(DelegatingResultSet.java:239)
at org.hibernate.type.LongType.get(LongType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:759)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:292)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
Name and version of the database you are using:
Oracle 9
The generated SQL (show_sql=true):
select * from shark_resource where deleted = 0 ;
Hello,
trying to execcute the above mentionned native sql query, to get hibernate object (as mentionned in documentation:
http://www.hibernate.org/hib_docs/refer ... rysql.html ), i get this sql error. "invalid column name". Upon further analysis, it seems that hibernate is trying to find an "objectId0_" column, which doesn't exist in the query. There is no mention of such behaviour in documentation.
Can someone give me information on how to create native sql query to return hibernate pojos? I need to use native query in this case, because the where part of query is provided by caller, and the caller is independant on hibernate (it just rely on a database storing implementation), and this caller use sql where statement in some calls.