Are Hibernate Named Queries precompiled in the true sense?

眉间皱痕 提交于 2020-02-26 06:34:27

问题


Pre-compiled queries are compiled and cached in advance by DB vendor (like oracle,sql server etc) so that they can be faster for successive calls like prepared statement.

In Hibernate Named queries are said to be pre-compiled at web server start up. Does it means all queries are fired at server startup itself so that they can be pre-compiled by DB vendor or pre-compilation has different meaning in hibernate context?


回答1:


  1. The Hibernate Named queries are expressed in an object query language (JPQL or HQL), so Hibernate needs to translate them to SQL first. The named queries are stored in a NamedQueryRepository and each query is represented by a NamedQueryDefinition.

    Because the user can dynamically add filters, query result limits, locks and hints, Hibernate cannot pre-compile the HQL/JPQL until execution time.

  2. Hibernate also uses a PreparedStatement for each SELECT and DML statement so you can also get database statement precompilation if the JDBC driver supports it and doesn't emulate the prepare phase by multiplexing the prepare and the execute in a single database request (e.g. MySQL, PostgreSQL).



来源:https://stackoverflow.com/questions/27565706/are-hibernate-named-queries-precompiled-in-the-true-sense

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