Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes Using Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Using "FORCE INDEX" clause in HQL" Watch "Using "FORCE INDEX" clause in HQL" New topic

Using "FORCE INDEX" clause in HQL

Renato Veneroso

Joined: Mar 18, 2004
Posts: 12
Hello people,

Does anybody know whether is possible to include the "FORCE INDEX" clause in an HQL sentence? Due to what seems to be a MySQL bug the best index of a table has not been used and this is causing performance loss. The problem can be fixed in pure SQL using the clause "FORCE INDEX" but in HQL it cannot be used (at least not explicitly).

Is there a way I can re-write my HQL so that it forces the use of specific index?

Thanks in advance.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You could just use a SQL query, since Hibernate supports querying with SQL. You would be making your Hibernate code platform specific if you did this though.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Don't get me started about those stupid light bulbs.
subject: Using "FORCE INDEX" clause in HQL
Similar Threads
Hibernate LEFT JOIN FETCH WITH syntax
Criteria API
hibernate Criteria "fast" search
ResultSet JavaBean
Using Right outer Joins in Hibernate with My SQL.