问题
I have a jpa (openjpa-2.2.1) namedquery that has some hardcoded literals (ex: a.status <> 'X') - the problem is at runtime the generated query is actually a prepared statement (a.status <> ?)
Is there a way to force JPA run the query as is? (i would like to keep it as namedquery, not implement it as native query or other ways)
I would like to run the query as is because of performance reasons - the static query runs in a db client in about 2 seconds while the prepared statement fired from JUNIT in 3-4 mins. (we had performance problems in the past with prepared statements for some queries and changing to static queries did the trick)
回答1:
Set the query hint openjpa.hint.UseLiteralInSQL=true
(ref). See this IBM technote for more details.
来源:https://stackoverflow.com/questions/28317482/jpa-namedquery-with-literals-changed-to-prepared-statement