jpa namedquery with literals changed to prepared statement

大城市里の小女人 提交于 2019-12-24 13:15:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!