<p>Can anyone point me out, how can I parse/evaluate HQL and get map where key is table alias and value - full qualified class name.</p>

<p>E.g. for HQL</p>

<blockquote>
  <p>SELECT a.id from Foo a INNER JOIN a.test b</p>
</blockquote>

<p>I wish to have pairs:</p>

<p>a, package1.Foo</p>

<p>b. package2.TestClassName</p>

<p>It's relatively easy to do for result set</p>

<blockquote>
<pre><code>HQLQueryPlan hqlPlan = ((SessionFactoryImpl)sf).getQueryPlanCache().getHQLQueryPlan( getQueryString(), false, ((SessionImpl)session).getEnabledFilters() );
String[] aliases = hqlPlan.getReturnMetadata().getReturnAliases();
Type[] types = hqlPlan.getReturnMetadata().getReturnTypes();
</code></pre>
</blockquote>

<p>See <a href="http://www.hibernate.org/389.html" rel="nofollow noreferrer">details here</a>.</p>

Hardly a good way of doing it, but it seems you can get the AST through some internal interfaces and traverse this:
```
```
QueryTranslator[] translators = hqlPlan.getTranslators();
AST ast = (AST)((QueryTranslatorImpl)translators[0]).getSqlAST();
    new NodeTraverser(new NodeTraverser.VisitationStrategy() {
    public void visit(AST node) {
        if(node.getType() == SqlTokenTypes.FROM_FRAGMENT || node.getType() == SqlTokenTypes.JOIN_FRAGMENT) {
            FromElement id = (FromElement)node;
            System.out.println(node+": "+id.getClassAlias()+" - "+id.getClassName());
        }
    }
}).traverseDepthFirst(ast);
```
```
So this seems to retrieve the alias-mappings from the compiled query, but I would be very careful using this solution: it typecasts objects to subclasses not usually visible to a hibernate-client and interprets the AST based on guessing the semantics of the different nodes.  This might not work on all HQL-statements, and might not work, or have different behaviour, on a future hibernate-version.