0

I am using criteria API in my project but the query which is created from hibernate is very slow.

When I run the explain on the query I found that the required index is not being used. So I tried to use "use index()" clause provided by MYSQL and the query took only 5 sec. which was taking 70 sec.

But the issue is I am using criteria API and wanted to know that is there any option to use "use index()" clause in criteria API

Himanshu
  • 4,327
  • 16
  • 31
  • 39
Priyank
  • 1
  • 1
  • 5

1 Answers1

0

Although this solution was tested with HQL, it may work with Criteria API too.

You basically define a new Hibernate function, so for this HQL:

select table 
from MyTable table 
where useindex(table, my_index) is true and table.feature is not null

You'd get this SQL:

select table 
from MyTable table 
where useindex(table, my_index) is true and table.feature is not null
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911