private void initStatementString(
      final String projection,
      final String condition,
      final String orderBy,
      final String groupBy,
      final LockMode lockMode)
      throws MappingException {

    final int joins = countEntityPersisters(associations);
    suffixes = BasicLoader.generateSuffixes(joins + 1);

    JoinFragment ojf = mergeOuterJoins(associations);

    Select select =
        new Select(getDialect())
            .setLockMode(lockMode)
            .setSelectClause(
                projection == null
                    ? persister.selectFragment(alias, suffixes[joins]) + selectString(associations)
                    : projection)
            .setFromClause(
                getDialect().appendLockHint(lockMode, persister.fromTableFragment(alias))
                    + persister.fromJoinFragment(alias, true, true))
            .setWhereClause(condition)
            .setOuterJoins(
                ojf.toFromFragmentString(), ojf.toWhereFragmentString() + getWhereFragment())
            .setOrderByClause(orderBy(associations, orderBy))
            .setGroupByClause(groupBy);

    if (getFactory().getSettings().isCommentsEnabled()) {
      select.setComment(getComment());
    }
    sql = select.toStatementString();
  }