JPA namedquery的原义改为已准备好的语句 [英] jpa namedquery with literals changed to prepared statement
问题描述
我有一个名为jpa(openjpa-2.2.1)的查询,该查询具有一些硬编码的文字(例如:a.status<>'X')-问题是在运行时生成的查询实际上是一个准备好的语句(a.状态<>?)
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 <> ?)
是否有一种方法可以强制JPA按原样运行查询?(我想将其保留为namedquery,而不是将其实现为本机查询或其他方式)
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)
由于性能原因,我想按原样运行查询-静态查询在db客户端中运行约2秒钟,而准备好的语句在3-4分钟内从JUNIT触发. (过去,我们通过为某些查询准备语句而出现性能问题,而更改为静态查询则可以解决问题)
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)
推荐答案
设置查询提示openjpa.hint.UseLiteralInSQL=true
(此IBM技术说明.
Set the query hint openjpa.hint.UseLiteralInSQL=true
(ref). See this IBM technote for more details.
这篇关于JPA namedquery的原义改为已准备好的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!