public class

SQLProjection

extends Object
implements Projection
java.lang.Object
   ↳ org.hibernate.criterion.SQLProjection

Class Overview

A SQL fragment. The string {alias} will be replaced by the alias of the root entity.

Summary

Protected Constructors
SQLProjection(String sql, String[] columnAliases, Type[] types)
SQLProjection(String sql, String groupBy, String[] columnAliases, Type[] types)
Public Methods
String[] getAliases()
Get the criteria-level aliases for this projection (ie.
String[] getColumnAliases(int loc)
Get the SQL column aliases used by this projection for the columns it writes for inclusion into the SELECT clause (toSqlString(Criteria, int, CriteriaQuery).
String[] getColumnAliases(String alias, int loc)
Get the SQL column aliases used by this projection for the columns it writes for inclusion into the SELECT clause (toSqlString(Criteria, int, CriteriaQuery) for a particular criteria-level alias.
Type[] getTypes(String alias, Criteria crit, CriteriaQuery criteriaQuery)
Get the return types for a particular user-visible alias.
Type[] getTypes(Criteria crit, CriteriaQuery criteriaQuery)
Types returned by the rendered SQL fragment.
boolean isGrouped()
Is this projection fragment (SELECT clause) also part of the GROUP BY
String toGroupSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
Render the SQL fragment to be used in the GROUP BY clause
String toSqlString(Criteria criteria, int loc, CriteriaQuery criteriaQuery)
Render the SQL fragment to be used in the SELECT clause.
String toString()
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.hibernate.criterion.Projection

Protected Constructors

protected SQLProjection (String sql, String[] columnAliases, Type[] types)

protected SQLProjection (String sql, String groupBy, String[] columnAliases, Type[] types)

Public Methods

public String[] getAliases ()

Get the criteria-level aliases for this projection (ie. the ones that will be passed to the ResultTransformer)

Returns
  • The aliases

public String[] getColumnAliases (int loc)

Get the SQL column aliases used by this projection for the columns it writes for inclusion into the SELECT clause (toSqlString(Criteria, int, CriteriaQuery). Hibernate always uses column aliases to extract data from the JDBC java.sql.ResultSet, so it is important that these be implemented correctly in order for Hibernate to be able to extract these val;ues correctly.

Parameters
loc Just as in toSqlString(Criteria, int, CriteriaQuery), represents the number of columns rendered prior to this projection.
Returns
  • The columns aliases.

public String[] getColumnAliases (String alias, int loc)

Get the SQL column aliases used by this projection for the columns it writes for inclusion into the SELECT clause (toSqlString(Criteria, int, CriteriaQuery) for a particular criteria-level alias.

Parameters
alias The criteria-level alias
loc Just as in toSqlString(Criteria, int, CriteriaQuery), represents the number of columns rendered prior to this projection.
Returns
  • The columns aliases pertaining to a particular criteria-level alias; expected to return null if this projection does not understand this alias.

public Type[] getTypes (String alias, Criteria crit, CriteriaQuery criteriaQuery)

Get the return types for a particular user-visible alias.

Differs from getTypes(org.hibernate.Criteria, CriteriaQuery) in that here we are only interested in the types related to the given criteria-level alias.

Parameters
alias The criteria-level alias for which to find types.
crit The local criteria to which this project is attached (for resolution).
criteriaQuery The overall criteria query instance.
Returns
  • The return types; expected to return null if this projection does not understand this alias.

public Type[] getTypes (Criteria crit, CriteriaQuery criteriaQuery)

Types returned by the rendered SQL fragment. In other words what are the types that would represent the values this projection asked to be pulled into the result set?

Parameters
crit The local criteria to which this project is attached (for resolution).
criteriaQuery The overall criteria query instance.
Returns
  • The return types.

public boolean isGrouped ()

Is this projection fragment (SELECT clause) also part of the GROUP BY

Returns
  • True if the projection is also part of the GROUP BY; false otherwise.

public String toGroupSqlString (Criteria criteria, CriteriaQuery criteriaQuery)

Render the SQL fragment to be used in the GROUP BY clause

Parameters
criteria The local criteria to which this project is attached (for resolution).
criteriaQuery The overall criteria query instance.
Returns
  • The SQL fragment to plug into the GROUP BY

public String toSqlString (Criteria criteria, int loc, CriteriaQuery criteriaQuery)

Render the SQL fragment to be used in the SELECT clause.

Parameters
criteria The local criteria to which this project is attached (for resolution).
loc The number of columns rendered in the SELECT clause before this projection. Generally speaking this is useful to ensure uniqueness of the individual columns aliases.
criteriaQuery The overall criteria query instance.
Returns
  • The SQL fragment to plug into the SELECT

public String toString ()