1

I have a question.

Does the JPA(Hibernate) use a preparedStatement internally when using native update query?

Query query = EntityManager.createNativeQuery(updateSql);

//... some other codes here

query.setParameter(1, "column1");
query.setParameter(2, "column2");

query.executeUpdate();

Does the updateSql pre-compiled?

  • Yes, JPA engines use prepared statements. – JB Nizet Nov 10 '18 at 12:17
  • I've dug into Hibernate codes, but I couldn't find the part of making preparedStatement. Could anyone tell me how we can convince that? – Yonghee Lee Nov 10 '18 at 12:22
  • Just enable SQL logging, and you'll see the SQL, with the `?` placeholders. – JB Nizet Nov 10 '18 at 12:26
  • I think [here](https://github.com/hibernate/hibernate-orm) you can find proof. – pirho Nov 10 '18 at 12:26
  • https://github.com/hibernate/hibernate-orm/blob/e5dc635a52362f69b69acb8d5b166b69b165dbbd/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/StatementPreparer.java – JB Nizet Nov 10 '18 at 12:28
  • thx guys. But I still couldn't find the related some codes with executeUpdate and StatementPrepare. Does the "?" placeholder can be proof of pre-compiled SQL? – Yonghee Lee Nov 10 '18 at 12:55

0 Answers0