Top Description Inners Methods
org.hibernate

public Interface SQLQuery

extends Query
Known Direct Implementers
org.hibernate.impl.SQLQueryImpl
Imports
org.hibernate.type.Type

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:

Authors
Gavin King, Steve Ebersole

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
SQLQuery.FetchReturn

Allows access to further control how join fetch returns are mapped back from result sets

public static interface
SQLQuery.ReturnProperty

Allows access to further control how properties within a root or join fetch are mapped back from the result set.

public static interface
SQLQuery.RootReturn

Allows access to further control how root returns are mapped back from result sets

Method Summary

Modifier and TypeMethod and Description
public SQLQuery

Returns:

this, for method chaining
addEntity
(String
The entity name that is the root return of the query.
entityName
)

Declare a "root" entity, without specifying an alias.

public SQLQuery

Returns:

this, for method chaining
addEntity
(String
The SQL table alias
tableAlias
,
String
The entity name
entityName
)

Declare a "root" entity

public SQLQuery

Returns:

this, for method chaining
addEntity
(String
The SQL table alias
tableAlias
,
String
The entity name
entityName
,
LockMode
The lock mode for this return.
lockMode
)

Declare a "root" entity, specifying a lock mode

public SQLQuery

Returns:

this, for method chaining
addEntity
(Class<T>
The java type of the entity to add as a root
entityType
)

Declare a "root" entity, without specifying an alias.

public SQLQuery

Returns:

this, for method chaining
addEntity
(String
The SQL table alias
tableAlias
,
Class<T>
The java type of the entity to add as a root
entityType
)

Declare a "root" entity

public SQLQuery

Returns:

this, for method chaining
addEntity
(String
The SQL table alias
tableAlias
,
Class<T>
The entity name
entityName
,
LockMode
The lock mode for this return.
lockMode
)

Declare a "root" entity, specifying a lock mode

public SQLQuery.FetchReturn

Returns:

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

Declare a join fetch result.

public SQLQuery

Returns:

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

Declare a join fetch result.

public SQLQuery

Returns:

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

Declare a join fetch result.

public SQLQuery

Returns:

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

Declare a join fetch result, specifying a lock mode

public SQLQuery.RootReturn

Returns:

The return config object for further control.
addRoot
(String
The SQL table alias to map to this entity
tableAlias
,
String
The name of the entity.
entityName
)

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

public SQLQuery.RootReturn

Returns:

The return config object for further control.
addRoot
(String
The SQL table alias to map to this entity
tableAlias
,
Class<T>
The java type of the entity.
entityType
)

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

public SQLQuery

Returns:

this, for method chaining
addScalar
(String
The column alias in the result-set to be processed as a scalar result
columnAlias
)

Declare a scalar query result.

public SQLQuery

Returns:

this, for method chaining
addScalar
(String
The column alias in the result-set to be processed as a scalar result
columnAlias
,
Type
The Hibernate type as which to treat the value.
type
)

Declare a scalar query result.

public SQLQuery

Returns:

this, for method chaining
addSynchronizedEntityClass
(Class<T>
The class of the entity upon whose defined query spaces we should additionally synchronize.
entityClass
)

Adds an entity for (a) auto-flush checking and (b) query result cache invalidation checking.

public SQLQuery

Returns:

this, for method chaining
addSynchronizedEntityName
(String
The name of the entity upon whose defined query spaces we should additionally synchronize.
entityName
)

Adds an entity name for (a) auto-flush checking and (b) query result cache invalidation checking.

public SQLQuery

Returns:

this, for method chaining
addSynchronizedQuerySpace
(String
The query space to be auto-flushed for this query.
querySpace
)

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

public SQLQuery

Returns:

this, for method chaining
setResultSetMapping
(String
The name of the mapping to use.
name
)

Use a predefined named result-set mapping.

Inherited from org.hibernate.Query:
executeUpdategetNamedParametersgetQueryStringgetReturnAliasesgetReturnTypesisReadOnlyiteratelistscrollscrollsetBigDecimalsetBigDecimalsetBigIntegersetBigIntegersetBinarysetBinarysetBooleansetBooleansetBytesetBytesetCacheablesetCacheModesetCacheRegionsetCalendarsetCalendarsetCalendarDatesetCalendarDatesetCharactersetCharactersetCommentsetDatesetDatesetDoublesetDoublesetEntitysetEntitysetFetchSizesetFirstResultsetFloatsetFloatsetFlushModesetIntegersetIntegersetLocalesetLocalesetLockModesetLockOptionssetLongsetLongsetMaxResultssetParametersetParametersetParametersetParametersetParameterListsetParameterListsetParameterListsetParameterListsetParameterssetPropertiessetPropertiessetReadOnlysetResultTransformersetSerializablesetSerializablesetShortsetShortsetStringsetStringsetTextsetTextsetTimesetTimesetTimeoutsetTimestampsetTimestampuniqueResult

Method Detail

addEntityback to summary
public 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 if you need further control of the mapping

Parameters
entityName:String

The entity name that is the root return of the query.

Returns:SQLQuery

this, for method chaining

addEntityback to summary
public SQLQuery addEntity(String tableAlias, String entityName)

Declare a "root" entity

Parameters
tableAlias:String

The SQL table alias

entityName:String

The entity name

Returns:SQLQuery

this, for method chaining

addEntityback to summary
public SQLQuery addEntity(String tableAlias, String entityName, LockMode lockMode)

Declare a "root" entity, specifying a lock mode

Parameters
tableAlias:String

The SQL table alias

entityName:String

The entity name

lockMode:LockMode

The lock mode for this return.

Returns:SQLQuery

this, for method chaining

addEntityback to summary
public SQLQuery addEntity(Class<T> 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:Class<T>

The java type of the entity to add as a root

Returns:SQLQuery

this, for method chaining

addEntityback to summary
public SQLQuery addEntity(String tableAlias, Class<T> entityType)

Declare a "root" entity

Parameters
tableAlias:String

The SQL table alias

entityType:Class<T>

The java type of the entity to add as a root

Returns:SQLQuery

this, for method chaining

addEntityback to summary
public SQLQuery addEntity(String tableAlias, Class<T> entityName, LockMode lockMode)

Declare a "root" entity, specifying a lock mode

Parameters
tableAlias:String

The SQL table alias

entityName:Class<T>

The entity name

lockMode:LockMode

The lock mode for this return.

Returns:SQLQuery

this, for method chaining

addFetchback to summary
public SQLQuery.FetchReturn addFetch(String tableAlias, String ownerTableAlias, String joinPropertyName)

Declare a join fetch result.

Parameters
tableAlias:String

The SQL table alias for the data to be mapped to this fetch

ownerTableAlias:String

Identify the table alias of the owner of this association. Should match the alias of a previously added root or fetch

joinPropertyName:String

The name of the property being join fetched.

Returns:SQLQuery.FetchReturn

The return config object for further control.

Since
3.6
addJoinback to summary
public SQLQuery addJoin(String tableAlias, String path)

Declare a join fetch result.

Parameters
tableAlias:String

The SQL table alias for the data to be mapped to this fetch

path:String

The association path ([owner-alias].[property-name]).

Returns:SQLQuery

this, for method chaining

addJoinback to summary
public SQLQuery addJoin(String tableAlias, String ownerTableAlias, String joinPropertyName)

Declare a join fetch result.

Parameters
tableAlias:String

The SQL table alias for the data to be mapped to this fetch

ownerTableAlias:String

Identify the table alias of the owner of this association. Should match the alias of a previously added root or fetch

joinPropertyName:String

The name of the property being join fetched.

Returns:SQLQuery

this, for method chaining

Since
3.6
addJoinback to summary
public SQLQuery addJoin(String tableAlias, String path, LockMode lockMode)

Declare a join fetch result, specifying a lock mode

Parameters
tableAlias:String

The SQL table alias for the data to be mapped to this fetch

path:String

The association path ([owner-alias].[property-name]).

lockMode:LockMode

The lock mode for this return.

Returns:SQLQuery

this, for method chaining

addRootback to summary
public SQLQuery.RootReturn addRoot(String tableAlias, String entityName)

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

Parameters
tableAlias:String

The SQL table alias to map to this entity

entityName:String

The name of the entity.

Returns:SQLQuery.RootReturn

The return config object for further control.

Since
3.6
addRootback to summary
public SQLQuery.RootReturn addRoot(String tableAlias, Class<T> entityType)

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

Parameters
tableAlias:String

The SQL table alias to map to this entity

entityType:Class<T>

The java type of the entity.

Returns:SQLQuery.RootReturn

The return config object for further control.

Since
3.6
addScalarback to summary
public 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:String

The column alias in the result-set to be processed as a scalar result

Returns:SQLQuery

this, for method chaining

addScalarback to summary
public SQLQuery addScalar(String columnAlias, Type type)

Declare a scalar query result.

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

Parameters
columnAlias:String

The column alias in the result-set to be processed as a scalar result

type:Type

The Hibernate type as which to treat the value.

Returns:SQLQuery

this, for method chaining

addSynchronizedEntityClassback to summary
public SQLQuery addSynchronizedEntityClass(Class<T> entityClass) throws MappingException

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

Parameters
entityClass:Class<T>

The class of the entity upon whose defined query spaces we should additionally synchronize.

Returns:SQLQuery

this, for method chaining

Exceptions
MappingException:
Indicates the given class could not be resolved as an entity
addSynchronizedEntityNameback to summary
public SQLQuery addSynchronizedEntityName(String entityName) throws MappingException

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

Parameters
entityName:String

The name of the entity upon whose defined query spaces we should additionally synchronize.

Returns:SQLQuery

this, for method chaining

Exceptions
MappingException:
Indicates the given name could not be resolved as an entity
addSynchronizedQuerySpaceback to summary
public SQLQuery addSynchronizedQuerySpace(String querySpace)

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

Parameters
querySpace:String

The query space to be auto-flushed for this query.

Returns:SQLQuery

this, for method chaining

setResultSetMappingback to summary
public 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:String

The name of the mapping to use.

Returns:SQLQuery

this, for method chaining

org.hibernate back to summary

public Interface SQLQuery.FetchReturn

Known Direct Implementers
org.hibernate.impl.SQLQueryImpl.FetchReturnBuilder

Allows access to further control how join fetch returns are mapped back from result sets

Method Summary

Modifier and TypeMethod and Description
public SQLQuery.FetchReturn

Returns:

this, for method chaining
addProperty
(String
The name of the property.
propertyName
,
String
The name of the column
columnAlias
)

Add a simple property-to-one-column mapping

public SQLQuery.ReturnProperty

Returns:

The config object for further control.
addProperty
(String
The name of the property.
propertyName
)

Add a property, presumably with more than one column.

public SQLQuery.FetchReturn

Returns:

this, for method chaining
setLockMode
(LockMode
The new lock mode.
lockMode
)

Set the lock mode for this return

Method Detail

addPropertyback to summary
public SQLQuery.FetchReturn addProperty(String propertyName, String columnAlias)

Add a simple property-to-one-column mapping

Parameters
propertyName:String

The name of the property.

columnAlias:String

The name of the column

Returns:SQLQuery.FetchReturn

this, for method chaining

addPropertyback to summary
public SQLQuery.ReturnProperty addProperty(String propertyName)

Add a property, presumably with more than one column.

Parameters
propertyName:String

The name of the property.

Returns:SQLQuery.ReturnProperty

The config object for further control.

setLockModeback to summary
public SQLQuery.FetchReturn setLockMode(LockMode lockMode)

Set the lock mode for this return

Parameters
lockMode:LockMode

The new lock mode.

Returns:SQLQuery.FetchReturn

this, for method chaining

org.hibernate back to summary

public Interface SQLQuery.ReturnProperty


Allows access to further control how properties within a root or join fetch are mapped back from the result set. Generally used in composite value scenarios.

Method Summary

Modifier and TypeMethod and Description
public SQLQuery.ReturnProperty

Returns:

this, for method chaining
addColumnAlias
(String
The column alias.
columnAlias
)

Add a column alias to this property mapping.

Method Detail

addColumnAliasback to summary
public SQLQuery.ReturnProperty addColumnAlias(String columnAlias)

Add a column alias to this property mapping.

Parameters
columnAlias:String

The column alias.

Returns:SQLQuery.ReturnProperty

this, for method chaining

org.hibernate back to summary

public Interface SQLQuery.RootReturn

Known Direct Implementers
org.hibernate.impl.SQLQueryImpl.RootReturnBuilder

Allows access to further control how root returns are mapped back from result sets

Method Summary

Modifier and TypeMethod and Description
public SQLQuery.RootReturn

Returns:

this, for method chaining
addProperty
(String
The name of the property.
propertyName
,
String
The name of the column
columnAlias
)

Add a simple property-to-one-column mapping

public SQLQuery.ReturnProperty

Returns:

The config object for further control.
addProperty
(String
The name of the property.
propertyName
)

Add a property, presumably with more than one column.

public SQLQuery.RootReturn

Returns:

this, for method chaining
setDiscriminatorAlias
(String
The discriminator column alias
columnAlias
)

Name the column alias that identifies the entity's discriminator

public SQLQuery.RootReturn

Returns:

this, for method chaining
setLockMode
(LockMode
The new lock mode.
lockMode
)

Set the lock mode for this return

Method Detail

addPropertyback to summary
public SQLQuery.RootReturn addProperty(String propertyName, String columnAlias)

Add a simple property-to-one-column mapping

Parameters
propertyName:String

The name of the property.

columnAlias:String

The name of the column

Returns:SQLQuery.RootReturn

this, for method chaining

addPropertyback to summary
public SQLQuery.ReturnProperty addProperty(String propertyName)

Add a property, presumably with more than one column.

Parameters
propertyName:String

The name of the property.

Returns:SQLQuery.ReturnProperty

The config object for further control.

setDiscriminatorAliasback to summary
public SQLQuery.RootReturn setDiscriminatorAlias(String columnAlias)

Name the column alias that identifies the entity's discriminator

Parameters
columnAlias:String

The discriminator column alias

Returns:SQLQuery.RootReturn

this, for method chaining

setLockModeback to summary
public SQLQuery.RootReturn setLockMode(LockMode lockMode)

Set the lock mode for this return

Parameters
lockMode:LockMode

The new lock mode.

Returns:SQLQuery.RootReturn

this, for method chaining