java 休眠。ClassicQueryTranslatorFactory 与 ASTQueryTranslatorFactory 对比

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9909709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 22:52:06  来源:igfitidea点击:

Hibernate. ClassicQueryTranslatorFactory vs ASTQueryTranslatorFactory

javahibernateparsing

提问by Stanislav Bashkyrtsev

What's the difference between those query translators (I mean differences for me as a Hibernate user). Some blogs on the internet say that ANTLR-based translator is faster. But I deem that if one of them was clearly better, then Hibernate developers would remove the other one. So.. what's the difference and why do we have both of them? In what situations should I choose first or second? In what situations I shouldn't choose one of translators?

这些查询翻译器之间有什么区别(我的意思是作为 Hibernate 用户的我的区别)。互联网上的一些博客说基于 ANTLR 的翻译器速度更快。但我认为,如果其中一个明显更好,那么 Hibernate 开发人员会删除另一个。那么..有什么区别,为什么我们同时拥有它们?在什么情况下我应该选择第一或第二?在什么情况下我不应该选择其中一位翻译?

回答by ManuPK

It is an internal hibernate configuration; which got implemented when it got upgraded to version 3. You should not be worried about changing it until unless there is any strong reason for it. Also with the latest versions I think you need to change its default value. But if you want you can test it for performance improvement as told below.

它是一个内部休眠配置;它在升级到版本 3 时得到了实施。除非有任何充分的理由,否则不必担心更改它。另外对于最新版本,我认为您需要更改其默认值。但是如果你愿意,你可以测试它的性能改进,如下所述。

From the Hibernate Core Migration Guide : 3.0;

来自Hibernate 核心迁移指南:3.0

Query Language Changes

New Parser - Hibernate3 comes with a brand-new, ANTLR-based HQL/SQL query translator. However, the Hibernate 2.1 query parser is still available. The query parser may be selected by setting the Hibernate property hibernate.query.factory_class. The possible values are org.hibernate.hql.ast.ASTQueryTranslatorFactory, for the new query parser, and org.hibernate.hql.classic.ClassicQueryTranslatorFactory, for the old parser. We are working hard to make the new query parser support all queries allowed by Hibernate 2.1.

However, we expect that many existing applications will need to use the Hibernate 2.1 parser during the migration phase. The Hibernate 1.x syntax "from f in class bar.Foo" is no longer supported, use "from bar.Foo as f" or "from bar.Foo f". Don't use dots in named HQL parameter names. Note: there is a known bug affecting dialects with theta-style outer joins (eg. OracleDialect for Oracle 8i, TimesTen dialect, Sybase11Dialect). Try to use a dialect which supports ANSI-style joins (eg. Oracle9Dialect), or fall back to the old query parser if you experience problems.

查询语言更改

新的解析器 - Hibernate3 带有一个全新的、基于 ANTLR 的 HQL/SQL 查询转换器。但是,Hibernate 2.1 查询解析器仍然可用。可以通过设置 Hibernate 属性 hibernate.query.factory_class 来选择查询解析器。可能的值为 org.hibernate.hql.ast.ASTQueryTranslatorFactory,用于新的查询解析器,以及 org.hibernate.hql.classic.ClassicQueryTranslatorFactory,用于旧的解析器。我们正在努力使新的查询解析器支持 Hibernate 2.1 允许的所有查询。

但是,我们预计许多现有应用程序将需要在迁移阶段使用 Hibernate 2.1 解析器。不再支持 Hibernate 1.x 语法“from f in class bar.Foo”,使用“from bar.Foo as f”或“from bar.Foo f”。不要在命名的 HQL 参数名称中使用点。注意:有一个已知的错误会影响具有 theta 样式外连接的方言(例如,Oracle 8i 的 OracleDialect、TimesTen 方言、Sybase11Dialect)。尝试使用支持 ANSI 样式连接的方言(例如 Oracle9Dialect),或者在遇到问题时回退到旧的查询解析器。

Here is Forum postand a blog postregarding this issue.

这是关于此问题的论坛帖子和博客帖子

Now coming to your questions;

现在来回答你的问题;

what's the difference and why do we have both of them?

有什么区别,为什么我们同时拥有它们?

As told in the change log, hibernate 3 replaces the ClassicQueryTranslatorFactorywith ASTQueryTranslatorFactory. It is an internal change and the users need not be wooried about it until the change breaks your application.

由于在更改日志中说,休眠3个替换ClassicQueryTranslatorFactoryASTQueryTranslatorFactory。这是一个内部更改,在更改破坏您的应用程序之前,用户无需担心它。

In what situations should I choose first or second?In what situations I shouldn't choose one of translators?

在什么情况下我应该选择第一或第二?在什么情况下我不应该选择一位翻译?

By default ASTQueryTranslatorFactoryis enabled, you should consider changing it only if any of your queries break while upgrading to version 3.

默认情况下ASTQueryTranslatorFactory是启用的,只有在升级到版本 3 时任何查询中断时,您才应该考虑更改它。

Once again, it a story of the past(2006 or so); the latest version of hibernate is 4.1 and the query translator must be stable by now. So 99% you do not have to change any thing.

再一次,这是一个过去的故事(2006年左右);hibernate 的最新版本是 4.1 并且查询翻译器现在必须稳定。所以 99% 你不需要改变任何东西。