eclipselink
eclipselink copied to clipboard
EntityManager#find don't support multiple query hints
Currently there is no way to execute the EntityManager e.g. entityManager#find with multiple query hints with the same keys because a Java map is expected.
One suggestion was to pass QueryHints comma separately. Is that possible? Are there any better suggestions? Here is the issue directly in the specification. A discussion which is the best way would be great. https://github.com/eclipse-ee4j/jpa-api/issues/306
+1 but subject of this issue should be EntityManager#find don't support multiple query hints of same type
Any news?
For the following:
@NamedQuery(
name="AllEmployees",
query="SELECT e FROM Employee e",
hints={
@QueryHint(name=QueryHints.QUERY_RESULTS_CACHE_SIZE, value="200"),
@QueryHint(name=QueryHints.QUERY_RESULTS_CACHE_SIZE, value="500")
}
)
should the result cache size be 700
, 500
, 200
or an error?
An error.
But this issue is more about how to specify multiple hints of the same type when using EntityManager.find(), e.g. for betch fetching?
Some require simple boolean value/string value, some a fixed-value string and combining multiple options at once may make no sense, others a number etc. So what particular option do you mean? Or do you think that something like @QueryHint(name=QueryHints.QUERY_RESULTS_CACHE_SIZE, value="200,500")
to use the same sample makes sense?
In general, if one needs to pass multiple query hints with the same keys to the query, then one should get a query and call setHint
on it multiple times, ie following way:
TypedQuery<Project> query = em.createQuery("SELECT p FROM Project p", Project.class);
query.setHint(QueryHints.BATCH, "p.teamMembers");
query.setHint(QueryHints.BATCH, "p.teamMembers.projects");
query.setHint(QueryHints.BATCH, "p.teamMembers.phoneNumbers.owner");
query.setHint(QueryHints.BATCH_TYPE, BatchFetchType.IN);
query.setHint(QueryHints.FETCH, "p.teamMembers.address");
query.setHint(QueryHints.FETCH, "p.teamMembers.phoneNumbers");
List<Project> results = query.getResultList();
instead of using em.find