protected PreparedStatement prepareStatementAndSetParameters(SQLSerializer serializer,
            boolean withKeys) throws SQLException {
        listeners.prePrepare(context);

        queryString = serializer.toString();
        constants = serializer.getConstants();
        logQuery(logger, queryString, constants);
        PreparedStatement stmt;
        if (withKeys) {
            if (entity.getPrimaryKey() != null) {
                String[] target = new String[entity.getPrimaryKey().getLocalColumns().size()];
                for (int i = 0; i < target.length; i++) {
                    Path<?> path = entity.getPrimaryKey().getLocalColumns().get(i);
                    String column = ColumnMetadata.getName(path);
                    column = configuration.getColumnOverride(entity.getSchemaAndTable(), column);
                    target[i] = column;
                }
                stmt = connection().prepareStatement(queryString, target);
            } else {
                stmt = connection().prepareStatement(queryString, Statement.RETURN_GENERATED_KEYS);
            }
        } else {
            stmt = connection().prepareStatement(queryString);
        }
        setParameters(stmt, serializer.getConstants(), serializer.getConstantPaths(),
                metadata.getParams());

        context.addPreparedStatement(stmt);
        listeners.prepared(context);
        return stmt;
    }
Execute the clause and return the generated key with the type of the
given path. If no rows were created, or the referenced column is not a
generated key, null is returned. Otherwise, the key of the first row is
returned.

@param <T>
@param path path for key
@return generated keys
querydsl-sql/src/main/java/com/querydsl/sql/dml/AbstractSQLInsertClause.java