jakartaee / jakartaee/persistence
Provide Dialect Specific Query Hints on Joins
- Dominant language
- Java
- Stars
- 268
- Forks
- 78
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 13
Description
When querying for a lazy loaded entity, most jpa implementations allow me to specify dialect specific hints, such as Hibernate's Query interface ([https://github.com/hibernate/hibernate-orm/blob/065859496dcc2d5a3144d67ba73b1c8116b56399/hibernate-core/src/main/java/org/hibernate/Query.java#L225](https://github.com/hibernate/hibernate-orm/blob/065859496dcc2d5a3144d67ba73b1c8116b56399/hibernate-core/src/main/java/org/hibernate/Query.java#L225))
This allows for very useful features DB providers employ such as Oracle's built-in caching mechanism, activated by specifying +RESULT_CACHE.
The problem comes when queries are generated to retrieve lazily loaded mappings since there is no mechanism to provide hints to those select queries.
I've requested the same need to Hibernate's team at ([https://hibernate.atlassian.net/browse/HHH-11618](https://hibernate.atlassian.net/browse/HHH-11618)) however this increasingly sounds more like something JPA_SPEC should support out of the box as projects like Hibernate and OpenJPA are struggling to define a default hint delivery mechanism, which also forces the developer to be locked to a specific implementation.
Below is how I imagined it might work to provide query hints to a lazily fetched entity:
```
//Consider the following: @Entity
public static class Employee {
@Id
@GeneratedValue
public long id;
@ManyToOne(fetch = FetchType.EAGER, fetchHints= {"+RESULT_CACHE"} )
public Department department;
}
```
Thank you for your consideration.
#### Affected Versions
[2.1.1]
Contributor guide
Research direction
No repository files or tests are named. Start by reviewing the JPA query-hint specification and the cited Hibernate Query interface, then compare how Hibernate and OpenJPA handle hints for lazy-loading selects. Done means defining and documenting a portable mechanism for dialect-specific hints on lazily fetched relationships.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100