Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用mysql';s";使用索引();hibernate标准中的子句?_Java_Mysql_Hibernate_Criteria Api - Fatal编程技术网

Java 如何使用mysql';s";使用索引();hibernate标准中的子句?

Java 如何使用mysql';s";使用索引();hibernate标准中的子句?,java,mysql,hibernate,criteria-api,Java,Mysql,Hibernate,Criteria Api,我在我的项目中使用CriteriaAPI,但是从hibernate创建的查询速度非常慢 当我对查询运行explain时,我发现没有使用所需的索引。所以我尝试使用MYSQL提供的“use index()”子句,查询只花了5秒。花了70秒 但问题是我正在使用criteria API,我想知道criteria API中是否有使用“use index()”子句的选项。尽管已使用HQL进行了测试,但它也可能与criteria API一起工作 您基本上定义了一个新的Hibernate函数,因此对于此HQL:

我在我的项目中使用CriteriaAPI,但是从hibernate创建的查询速度非常慢

当我对查询运行explain时,我发现没有使用所需的索引。所以我尝试使用MYSQL提供的
“use index()”
子句,查询只花了5秒。花了70秒

但问题是我正在使用criteria API,我想知道criteria API中是否有使用
“use index()”
子句的选项。尽管已使用HQL进行了测试,但它也可能与criteria API一起工作

您基本上定义了一个新的Hibernate函数,因此对于此HQL:

您将得到以下SQL:

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