Hibernate version:
3.0
Hi There,
I am generating an SQL query in two ways
1. Using a Criteria - works fine.
2. Using a native SQL query using createSQLQuery - does not work.
Using this approach I get the error:
[OraDriver] Column not found <ID>.
This is the code that executes the statement and then gets the results:
Code:
String query = sqlQuery.getQuery();
if( null == query ) {
return aList;
}
Map namedParams = sqlQuery.getNamedParams();
SQLQueryImpl queryImpl = (SQLQueryImpl)getSession().createSQLQuery(query);
queryImpl = (SQLQueryImpl)this.setSQLQueryNamedParameters(queryImpl, namedParams) .setParameter(SqlQueryContainer.fromRow_np, index + size, Hibernate.INTEGER) .setParameter(SqlQueryContainer.toRow_np, index, Hibernate.INTEGER);
aList = queryImpl.addEntity(A.class)
.list();
Note that the query passed to the createSQLQuery is exactly the same as below except it has named params instead of the ? i.e. I dont use object notation just plain old SQL. The query works fine if the innermost select uses select * from A instead of naming the columns (which I have to do for other reasons).
BOTH SQL STATEMENTS ARE EXACTLY THE SAME as proven by the hibernate debug output. The statement also runs fine in toad, no errors. Here is the statement:
select * from ( select row_.*, rownum rownum_ from ( select this_.ID as ID240_0_, this_.DESCRIPTION as DESCRIPT3_240_0_, this_.A_TYPE_ID as A4_240_0_, this_.ASSIGNED_DATE as ASSIGNED5_240_0_, this_.ASSIGNED_USER_ID as ASSIGNED6_240_0_, this_.CLEARED_TIME as CLEARED7_240_0_, this_.D_SOURCE_ID as DATA8_240_0_, this_.E_R_LOSS as ESTIMATED9_240_0_, this_.FROM_TIME as FROM10_240_0_, this_.PARENT_ID as PARENT11_240_0_, this_.REPORTED_TIME as REPORTED12_240_0_, this_.SEVERITY as SEVERITY240_0_, this_.STATUS as STATUS240_0_, this_.TO_TIME as TO15_240_0_, this_.O_R_LOSS as ORIGINAL16_240_0_, this_.FILE_CAUSED as FILE17_240_0_, this_.FILE_CLEARED as FILE18_240_0_, this_.EXPECTED_TIME as EXPECTED19_240_0_, this_.ACTUAL as ACTUAL240_0_, this_.HISTORICAL as HISTORICAL240_0_, this_.SECOND_FILE_CAUSED as SECOND22_240_0_, this_.FIRST_ACTUAL_VALUE as FIRST23_240_0_, this_.SECOND_ACTUAL_VALUE as SECOND24_240_0_, this_.M_P_ID as MONITORED25_240_0_, this_.THRESHOLD_DESCRIPTION as THRESHOLD26_240_0_, this_.CLASS as CLASS240_0_ from RO_A this_ where this_.STATUS in (?, ?) order by this_.E_R_LOSS asc ) row_ ) where rownum_ <= ? and rownum_ > ?
Any ideas????
thanks a lot,
- Paul.
Code:
Code:
Code: