final SessionImplementor session = ( (CriteriaImpl) criteria ).getSession(); //ugly!
final SessionFactoryImplementor factory = session.getFactory();
final OuterJoinLoadable persister = (OuterJoinLoadable) factory.getEntityPersister( criteriaImpl.getEntityOrClassName() );
CriteriaQueryTranslator innerQuery = new CriteriaQueryTranslator(
factory,
criteriaImpl,
criteriaImpl.getEntityOrClassName(), //implicit polymorphism not supported (would need a union)
criteriaQuery.generateSQLAlias(),
criteriaQuery
);
params = innerQuery.getQueryParameters(); //TODO: bad lifecycle....
types = innerQuery.getProjectedTypes();
//String filter = persister.filterFragment( innerQuery.getRootSQLALias(), session.getEnabledFilters() );
String sql = new Select( factory.getDialect() )
.setWhereClause( innerQuery.getWhereCondition() )
.setGroupByClause( innerQuery.getGroupBy() )
.setSelectClause( innerQuery.getSelect() )
.setFromClause(
persister.fromTableFragment( innerQuery.getRootSQLALias() ) +
persister.fromJoinFragment( innerQuery.getRootSQLALias(), true, false )
)
.toStatementString();
final StringBuffer buf = new StringBuffer()
.append( toLeftSqlString(criteria, criteriaQuery) );