# Inclusion of Oracle Hint

**URL:** <https://discourse.hibernate.org/t/inclusion-of-oracle-hint/1762>\
**Category:** Hibernate ORM\
**Created:** [November 21, 2018, 6:49pm UTC](https://discourse.hibernate.org/t/inclusion-of-oracle-hint/1762 "2018-11-21T18:49:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thunderman74](https://avatars.discourse-cdn.com/v4/letter/t/ac8455/32.png) [@thunderman74](https://discourse.hibernate.org/u/thunderman74)\
**Post date:** [November 21, 2018, 6:49pm UTC](https://discourse.hibernate.org/t/inclusion-of-oracle-hint/1762/1 "2018-11-21T18:49:39Z")

</div>

Hi all,

Does anyone know of a good way using Hibernate to include an Oracle hint (after the select keyword) in the sql statement?

Thank you in advance

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [November 21, 2018, 10:12pm UTC](https://discourse.hibernate.org/t/inclusion-of-oracle-hint/1762/2 "2018-11-21T22:12:43Z")

</div>

As explained in [this article](https://vladmihalcea.com/execution-plan-oracle-hibernate-query-hints/), you can use The `addQueryHint` method:

```auto
List<Long> postIds = entityManager
.createNativeQuery(
    "SELECT " +
    " p.id " +
    "FROM " +
    " post p " +
    "WHERE EXISTS ( " +
    " SELECT 1 " +
    " FROM " +
    " post_comment pc " +
    " WHERE " +
    " pc.post_id = p.id AND " +
    " pc.review = 'Bingo' " +
    ") " +
    "ORDER BY " +
    " p.title ")
.setFirstResult(pageStart)
.setMaxResults(pageSize)
.addQueryHint("GATHER_PLAN_STATISTICS")
.addQueryHint("POST_WITH_BINGO_COMMENTS")
.getResultList();

```
