JPA Entity use index hint

大兔子大兔子 提交于 2019-12-13 17:38:28

问题


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?


回答1:


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();


来源:https://stackoverflow.com/questions/10085450/jpa-entity-use-index-hint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!