jpa namedquery with literals changed to prepared s

2019-08-02 07:00发布

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条回答
戒情不戒烟
2楼-- · 2019-08-02 07:32

Set the query hint openjpa.hint.UseLiteralInSQL=true (ref). See this IBM technote for more details.

查看更多
登录 后发表回答