Search code examples
jpajdbcopenjpa

How can I tell JPA to use prepared statements (or dynamic sql)?


I do understand the advantages of prepared statments over dynamic sql as described in Difference between Statement and PreparedStatement.

However I'm not sure how to tell JPA to (not) use a prepared statement.

I have a number of named queries. Is JPA automatically using prepared statments for this? What about criteria API. My guess is that it's using dynamic sql?


Solution

  • I concur with Michele in that generally prepared statements are used by the underlying JPA provider/implementer. To assure that your statements are prepared and results cached (should you desire this) using standard JPA please see my response here:

    How to use PreparedStatement efficiently?