Is it possible to disable jpa hints per particular query?

倖福魔咒の 提交于 2019-12-10 12:21:47

问题


JPA, and in my particular case eclipselink, generates /*+ FIRST_ROWS */ in case of using query.setFirstResult()/query.setMaxResults():

SELECT * FROM (
  SELECT /*+ FIRST_ROWS */ a.*, ROWNUM rnum  FROM (
    SELECT * FROM TABLES INCLUDING JOINS, ORDERING, etc.) a
  WHERE ROWNUM <= 10 )
WHERE rnum > 0;

That forces Oracle to use nested loops instead of hash-joins. In general is has seance, but in my particular case it dramatically decrease performance.

Is it possible to disable hint usage/generation for a particular query?


回答1:


As @ibre5041 told, FIRST_ROWS hint is deprecated, in context of Oracle, FIRST_ROWS(N) should be used instead of it. In my case neither FIRST_ROW nor FIRST_ROW(N) is actually needed, so in order to tell eclipselink not to use outdated stuff, it's possible to specify oracle version within persistence.xml:

<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.Oracle11Platform" />

After adding this, I got strange error: Could not initialize class org.eclipse.persistence.platform.database.oracle.Oracle11Platform However, after I put ojdbcN.jar to domain/lib/ext the error has gone.

As a result, eclipselink generates query without FIRST_ROW hint, and Oracle uses better plan.



来源:https://stackoverflow.com/questions/36840776/is-it-possible-to-disable-jpa-hints-per-particular-query

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