I found out that it is important to specify the exact version of Oracle in the persistence.xml file. I am currently using EclipseLink as the persistence framework provider.
Oracle hints were introduced to speed up/optimize SQL queries. Starting with Oracle 10, some of them have become almost unecessary because the optimizer was greatly improved. Also, depending on the structure of the queries and the database design (use of primary keys or not, index are where they should be or not, etc), hints can be counterproductive since they slow down queries instead of speeding them up.
SELECT * FROM ( SELECT /*+ FIRST_ROWS */ a.*, ROWNUM rnum FROM ( SELECT col1, col2 from table1) a WHERE ROWNUM <= 20) WHERE rnum > 0;
This SQL query is used for pagination, was coded with JPA criteria and was generated by EclipseLink using ORACLE as the target database as specified in the following persistence.xml file :
<property name="eclipselink.target-database" value="Oracle" />
We use Oracle 11g. In order to indicate EclipseLink to produce SQL code for Oracle11, the target database should be ORACLE11, not ORACLE:
<property name="eclipselink.target-database" value="Oracle11" />
In that case, the SQL query generated no longer contains the FIRST_ROWS hint :
SELECT * FROM ( SELECT a.*, ROWNUM rnum FROM ( SELECT col1, col2 from table1) a WHERE ROWNUM <= 20) WHERE rnum > 0;
If we examine the source code of EclipseLink, we can see in OraclePlatform.java the initial value of the HINT variable :
<b>protected</b> String HINT = "/*+ FIRST_ROWS */ ";
In the Oracle10Platform class, which inherits from OraclePlatform, that value is overriden :
public Oracle10Platform(){ super(); //bug 374136: override setting the FIRST_ROWS hint as this is not needed on Oracle10g HINT = ""; }