Hibernate. ClassicQueryTranslatorFactory vs ASTQue

2019-02-13 13:47发布

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?

1条回答
Fickle 薄情
2楼-- · 2019-02-13 14:30

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.

查看更多
登录 后发表回答