休眠。 ClassicQueryTranslatorFactory与ASTQueryTranslatorFactory [英] Hibernate. ClassicQueryTranslatorFactory vs ASTQueryTranslatorFactory

查看:535
本文介绍了休眠。 ClassicQueryTranslatorFactory与ASTQueryTranslatorFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

内部休眠配置 ;它在升级到版本3时得以实施。除非有很强的理由,否则不应该担心要更改它。此外,对于最新版本,我认为您需要更改其默认值。但如果你想要的话,你可以测试它的性能改善,如下所示。



;


查询语言更改



新分析器 - 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 2.1分析器迁移阶段。不再支持Hibernate 1.x语法from class bar.Foo,使用from bar.Foo as f或from bar.Foo f。不要在命名的HQL参数名称中使用点。注意:有一个已知的影响方言的theta风格的外连接(例如OracleDialect for Oracle 8i,TimesTen方言,Sybase11Dialect)。尝试使用支持ANSI风格连接的方言(例如Oracle9Dialect),或者如果遇到问题,请回退到旧的查询分析器。


这里是论坛帖子和一个有关此问题的博客信息



现在回答您的问题;


有什么区别,为什么我们都有这两种? / b>

正如变更记录中所述,hibernate 3将 ClassicQueryTranslatorFactory 替换为 ASTQueryTranslatorFactory 。这是一个内部变化,用户不需要记住它,直到变化破坏你的应用程序。


在什么情况下我应该先选择或者第二个?在什么情况下我不应该选择一个翻译员?


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



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

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?

解决方案

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.

From the Hibernate Core Migration Guide : 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.

Here is Forum post and a blog post regarding 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 ClassicQueryTranslatorFactory with ASTQueryTranslatorFactory. It is an internal change and the users need not be wooried about it until the change breaks your application.

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

By default ASTQueryTranslatorFactory is enabled, you should consider changing it only if any of your queries break while upgrading to version 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.

这篇关于休眠。 ClassicQueryTranslatorFactory与ASTQueryTranslatorFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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