spring-data-jpa icon indicating copy to clipboard operation
spring-data-jpa copied to clipboard

Process spel values of @QueryHint

Open ujhazib opened this issue 2 years ago • 3 comments

Some query hints are very specific values, rather than a boolean, like a timeout on an SQL query. Usually it is not too hard wired in a production grade system but configurable. It is impossible to achieve this behavior with @QueryHints({@QueryHint...}) since the value of QueryHint is not going through on expression language lookup (which would help to get the value at least from a properties/yaml file). Another possibility I see, and it is somewhat covered in this ticket, is that the JpaRepository interface methods should support some kind of List<QueryHint> structure as an input so we can pass them in programatically when we call those methods.

ujhazib avatar Jul 21 '23 11:07 ujhazib

@ujhazib Can you show an example of a type of query hint you'd like to be able to apply in some repository definition?

gregturn avatar Jul 28 '23 21:07 gregturn

It should be noted that injecting a SpelExpressionParser into the objects that need it to do the evaluation is a bit tricky.

gregturn avatar Jul 28 '23 21:07 gregturn

Sorry for the slow feedback, was on vacation. One example would be

@QueryHints(
   { @QueryHint(name = org.hibernate.jpa.QueryHints.SPEC_HINT_TIMEOUT, "#{someConfigBean.someTimeoutSetting}") }
)

To detach the timeout setting from a binary compilation and to depend rather on a config file in this case.

ujhazib avatar Aug 01 '23 11:08 ujhazib