Hi Moshe,
There is no way to specify DB-specific SQL query hints when using HQL.
There was some discussion at some point of adding it as a feature, but nothing ever came of it.
http://forum.hibernate.org/viewtopic.php?t=928724
We hit this same issue a couple of years ago with Informix. (it uses comments after SELECT to specify hints just like Oracle does)
Rather than drop back down to using SQL queries as was the suggestion we received at the time, we decided to patch Hibernate to address the issue.
FYI, we modified org.hibernate.loader.Loader as follows...
Original Code
Code:
private String prependComment(String sql, QueryParameters parameters) {
String comment = parameters.getComment();
if ( comment == null ) {
return sql;
}
else {
return new StringBuffer( comment.length() + sql.length() + 5 )
.append( "/* " )
.append( comment )
.append( " */ " )
.append( sql )
.toString();
}
}
Patched Code:Code:
private String prependComment(String sql, QueryParameters parameters) {
String comment = parameters.getComment();
if ( comment == null ) {
return sql;
}
else {
return sql.replaceFirst("select ", "select /*" + comment + "*/ ");
}
}
Note that as a consequence of this, we have to re-apply this patch every time we upgrade Hibernate versions.
Regards,
Frank Grimes