public interface

SQLQuery

implements Query
org.hibernate.SQLQuery
Known Indirect Subclasses

Class Overview

Represents a "native sql" query and allows the user to define certain aspects about its execution, such as:

In terms of result-set mapping, there are 3 approaches to defining:

Summary

Nested Classes
interface SQLQuery.FetchReturn Allows access to further control how join fetch returns are mapped back from result sets  
interface SQLQuery.ReturnProperty Allows access to further control how properties within a root or join fetch are mapped back from the result set. 
interface SQLQuery.RootReturn Allows access to further control how root returns are mapped back from result sets  
Public Methods
abstract SQLQuery addEntity(String tableAlias, Class entityType)
Declare a "root" entity
abstract SQLQuery addEntity(String tableAlias, Class entityName, LockMode lockMode)
Declare a "root" entity, specifying a lock mode
abstract SQLQuery addEntity(String entityName)
Declare a "root" entity, without specifying an alias.
abstract SQLQuery addEntity(String tableAlias, String entityName)
Declare a "root" entity
abstract SQLQuery addEntity(String tableAlias, String entityName, LockMode lockMode)
Declare a "root" entity, specifying a lock mode
abstract SQLQuery addEntity(Class entityType)
Declare a "root" entity, without specifying an alias.
abstract SQLQuery.FetchReturn addFetch(String tableAlias, String ownerTableAlias, String joinPropertyName)
Declare a join fetch result.
abstract SQLQuery addJoin(String tableAlias, String ownerTableAlias, String joinPropertyName)
Declare a join fetch result.
abstract SQLQuery addJoin(String tableAlias, String path, LockMode lockMode)
Declare a join fetch result, specifying a lock mode
abstract SQLQuery addJoin(String tableAlias, String path)
Declare a join fetch result.
abstract SQLQuery.RootReturn addRoot(String tableAlias, String entityName)
Add a new root return mapping, returning a SQLQuery.RootReturn to allow further definition
abstract SQLQuery.RootReturn addRoot(String tableAlias, Class entityType)
Add a new root return mapping, returning a SQLQuery.RootReturn to allow further definition
abstract SQLQuery addScalar(String columnAlias, Type type)
Declare a scalar query result.
abstract SQLQuery addScalar(String columnAlias)
Declare a scalar query result.
abstract SQLQuery addSynchronizedEntityClass(Class entityClass)
Adds an entity for (a) auto-flush checking and (b) query result cache invalidation checking.
abstract SQLQuery addSynchronizedEntityName(String entityName)
Adds an entity name for (a) auto-flush checking and (b) query result cache invalidation checking.
abstract SQLQuery addSynchronizedQuerySpace(String querySpace)
Adds a query space (table name) for (a) auto-flush checking and (b) query result cache invalidation checking
abstract SQLQuery setResultSetMapping(String name)
Use a predefined named result-set mapping.
[Expand]
Inherited Methods
From interface org.hibernate.Query

Public Methods

public abstract SQLQuery addEntity (String tableAlias, Class entityType)

Declare a "root" entity

Parameters
tableAlias The SQL table alias
entityType The java type of the entity to add as a root
Returns
  • this, for method chaining

public abstract SQLQuery addEntity (String tableAlias, Class entityName, LockMode lockMode)

Declare a "root" entity, specifying a lock mode

Parameters
tableAlias The SQL table alias
entityName The entity name
lockMode The lock mode for this return.
Returns
  • this, for method chaining

public abstract SQLQuery addEntity (String entityName)

Declare a "root" entity, without specifying an alias. The expectation here is that the table alias is the same as the unqualified entity name

Use addRoot(String, Class) if you need further control of the mapping

Parameters
entityName The entity name that is the root return of the query.
Returns
  • this, for method chaining

public abstract SQLQuery addEntity (String tableAlias, String entityName)

Declare a "root" entity

Parameters
tableAlias The SQL table alias
entityName The entity name
Returns
  • this, for method chaining

public abstract SQLQuery addEntity (String tableAlias, String entityName, LockMode lockMode)

Declare a "root" entity, specifying a lock mode

Parameters
tableAlias The SQL table alias
entityName The entity name
lockMode The lock mode for this return.
Returns
  • this, for method chaining

public abstract SQLQuery addEntity (Class entityType)

Declare a "root" entity, without specifying an alias. The expectation here is that the table alias is the same as the unqualified entity name

Parameters
entityType The java type of the entity to add as a root
Returns
  • this, for method chaining

public abstract SQLQuery.FetchReturn addFetch (String tableAlias, String ownerTableAlias, String joinPropertyName)

Declare a join fetch result.

Parameters
tableAlias The SQL table alias for the data to be mapped to this fetch
ownerTableAlias Identify the table alias of the owner of this association. Should match the alias of a previously added root or fetch
joinPropertyName The name of the property being join fetched.
Returns
  • The return config object for further control.

public abstract SQLQuery addJoin (String tableAlias, String ownerTableAlias, String joinPropertyName)

Declare a join fetch result.

Parameters
tableAlias The SQL table alias for the data to be mapped to this fetch
ownerTableAlias Identify the table alias of the owner of this association. Should match the alias of a previously added root or fetch
joinPropertyName The name of the property being join fetched.
Returns
  • this, for method chaining

public abstract SQLQuery addJoin (String tableAlias, String path, LockMode lockMode)

Declare a join fetch result, specifying a lock mode

Parameters
tableAlias The SQL table alias for the data to be mapped to this fetch
path The association path ([owner-alias].[property-name]).
lockMode The lock mode for this return.
Returns
  • this, for method chaining

public abstract SQLQuery addJoin (String tableAlias, String path)

Declare a join fetch result.

Parameters
tableAlias The SQL table alias for the data to be mapped to this fetch
path The association path ([owner-alias].[property-name]).
Returns
  • this, for method chaining

public abstract SQLQuery.RootReturn addRoot (String tableAlias, String entityName)

Add a new root return mapping, returning a SQLQuery.RootReturn to allow further definition

Parameters
tableAlias The SQL table alias to map to this entity
entityName The name of the entity.
Returns
  • The return config object for further control.

public abstract SQLQuery.RootReturn addRoot (String tableAlias, Class entityType)

Add a new root return mapping, returning a SQLQuery.RootReturn to allow further definition

Parameters
tableAlias The SQL table alias to map to this entity
entityType The java type of the entity.
Returns
  • The return config object for further control.

public abstract SQLQuery addScalar (String columnAlias, Type type)

Declare a scalar query result.

Functions like <return-scalar/> in hbm.xml or javax.persistence.ColumnResult

Parameters
columnAlias The column alias in the result-set to be processed as a scalar result
type The Hibernate type as which to treat the value.
Returns
  • this, for method chaining

public abstract SQLQuery addScalar (String columnAlias)

Declare a scalar query result. Hibernate will attempt to automatically detect the underlying type.

Functions like <return-scalar/> in hbm.xml or javax.persistence.ColumnResult

Parameters
columnAlias The column alias in the result-set to be processed as a scalar result
Returns
  • this, for method chaining

public abstract SQLQuery addSynchronizedEntityClass (Class entityClass)

Adds an entity for (a) auto-flush checking and (b) query result cache invalidation checking. Same as addSynchronizedQuerySpace(String) for all tables associated with the given entity.

Parameters
entityClass The class of the entity upon whose defined query spaces we should additionally synchronize.
Returns
  • this, for method chaining
Throws
MappingException Indicates the given class could not be resolved as an entity

public abstract SQLQuery addSynchronizedEntityName (String entityName)

Adds an entity name for (a) auto-flush checking and (b) query result cache invalidation checking. Same as addSynchronizedQuerySpace(String) for all tables associated with the given entity.

Parameters
entityName The name of the entity upon whose defined query spaces we should additionally synchronize.
Returns
  • this, for method chaining
Throws
MappingException Indicates the given name could not be resolved as an entity

public abstract SQLQuery addSynchronizedQuerySpace (String querySpace)

Adds a query space (table name) for (a) auto-flush checking and (b) query result cache invalidation checking

Parameters
querySpace The query space to be auto-flushed for this query.
Returns
  • this, for method chaining

public abstract SQLQuery setResultSetMapping (String name)

Use a predefined named result-set mapping. This might be defined by a <result-set/> element in a Hibernate hbm.xml file or through a javax.persistence.SqlResultSetMapping annotation.

Parameters
name The name of the mapping to use.
Returns
  • this, for method chaining