JPA实体使用索引提示 [英] JPA Entity use index hint

查看:307
本文介绍了JPA实体使用索引提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的代码如下所示: b

  public static List< Transaction> findOnInactive(Date date){
return Transaction.find(
date =?and account in(select d.acctNb from account d
+where d.date =?and(d .inactive = true或d.blocked = true)
+group by d.acctNb),date,date).fetch();
}

运行生成的查询需要20秒。然而,使用



手动运行相同的查询,可以通过(INDEX(_dta_index_k1_1))...



只需要1秒。无论如何,我可以在我的JPA查询中指定索引提示?

解决方案

您需要使用本机SQL查询,如下所示:

  return JPA.em()。createNativeQuery(
select * from transaction with(INDEX(_dta_index_k1_1)).. 。,
Transaction.class).getResultList();


Is it possible to specify a database index hint on a play framework Entity query.

My code looks like:

public static List<Transaction> findOnInactive(Date date) {
    return Transaction.find(
            "date = ? and account in ( select d.acctNb from account d "
                    + " where d.date = ? and (d.inactive = true or d.blocked = true)" 
                    + " group by d.acctNb )", date, date).fetch();
}

Running the generated query takes 20 sec. However running the same query manually with

select * from transaction with (INDEX(_dta_index_k1_1)) ...

only take 1 sec. Anyway I could specify the index hint in my JPA query?

解决方案

You need to use native SQL query, something like this:

return JPA.em().createNativeQuery(
    "select * from transaction with (INDEX(_dta_index_k1_1)) ...",
    Transaction.class).getResultList();

这篇关于JPA实体使用索引提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆