Hibernate命名查询是否是在真正意义上预先编译的? [英] Are Hibernate Named Queries precompiled in the true sense?

查看:57
本文介绍了Hibernate命名查询是否是在真正意义上预先编译的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

预编译的查询由数据库供应商(例如oracle,sql server等)预先编译和缓存,因此它们可以更快 用于连续的调用,如预准备语句.

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.

在Hibernate中,命名查询据说是在Web服务器启动时预先编译的.这是否意味着所有查询都会在服务器启动时自动触发,以便数据库供应商可以对其进行预编译,或者在休眠上下文中进行预编译具有不同的含义?

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. Hibernate命名查询以对象查询语言(JPQL或HQL)表示,因此Hibernate需要首先将其转换为SQL.命名查询存储在 NamedQueryRepository ,每个查询均由 NamedQueryDefinition .

由于用户可以动态添加过滤器,查询结果限制,锁定和提示,因此Hibernate无法在执行之前预编译HQL/JPQL.

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

休眠还使用

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).

这篇关于Hibernate命名查询是否是在真正意义上预先编译的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆