code: private SQLQuery query(Class<?>... entity) {
  		SQLQuery q = session.createSQLQuery(sql);
  		if (entity.length == 1) {
  			q.addEntity(entity[0]);
  		}
  		for (Map.Entry<String, Type> scalar : scalars.entrySet()) {
  			q.addScalar(scalar.getKey(), scalar.getValue());
  		}
  		for (int i = 0; i < positionedParameters.length; i++) {
  			q.setParameter(i, positionedParameters[i]);
  		}
  		for (Map.Entry<String, Object> entry : namedParameters.entrySet()) {
  			Object value = entry.getValue();
  			if (Types.isArray(value)) {
  				Object[] parameter = (Object[]) value;
  				if (parameter.length == 0) {
  					throw new HibernateException(String.format("Invalid named parameter |%s|. Empty array.", entry.getKey()));
  				}
  				q.setParameterList(entry.getKey(), parameter);
  			} else if (Types.isCollection(value)) {
  				Collection<?> parameter = (Collection<?>) value;
  				if (parameter.isEmpty()) {
  					throw new HibernateException(String.format("Invalid named parameter |%s|. Empty list.", entry.getKey()));
  				}
  				q.setParameterList(entry.getKey(), parameter);
  			} else {
  				q.setParameter(entry.getKey(), value);
  			}
  		}
  		if (offset > 0) {
  			q.setFirstResult(offset);
  		}
  		if (rowsCount > 0) {
  			q.setMaxResults(rowsCount);
  		}
  		return q;
  	}
docs: Create SQL query object and initialize it from this helper properties.
  
  @param entity optional Hibernate entity.
  @return newly create SQL object.