treeStream.setTokenStream( tokens );
EntityNamesResolver entityNamesResolver = getDefinedEntityNames( session.getSessionFactory() );
FullTextSession fullTextSession = Search.getFullTextSession( session );
SearchFactoryImplementor searchFactory = (SearchFactoryImplementor) fullTextSession.getSearchFactory();
// Finally create the treewalker:
LuceneJPQLWalker walker = new LuceneJPQLWalker( treeStream, searchFactory, entityNamesResolver, namedParameters );
walker.statement();
org.apache.lucene.search.Query luceneQuery = walker.getLuceneQuery();
Class targetEntity = walker.getTargetEntity();
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery, targetEntity );
//Following options are mandatory to load matching entities without using a query
//(chicken and egg problem)
fullTextQuery.initializeObjectsWith( ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID );
return fullTextQuery;