Package org.hibernate.annotations
Annotation Interface SQLSelect
Specifies a custom SQL query to be used in place of the default SQL
generated by Hibernate when an entity or collection is loaded from the
database by id. This occurs when:
- an association to an entity is fetched lazily,
- a collection is fetched lazily, or
- when an entity is retrieved using
Session.get(java.lang.Class<T>, java.lang.Object)
orEntityManager.find(java.lang.Class<T>, java.lang.Object)
.
The given SQL statement must have exactly the number
of JDBC ?
parameters that Hibernate expects, that is, one for
each column of:
- the primary key, in the case of an entity, or
- the foreign key, in the case of a collection.
Optionally, an explicit result set mapping may be specified. It should have:
- a single
EntityResult
, if the SQL query loads an entity, one-to-many association, or many-to-many association, or - a single
ColumnResult
orConstructorResult
, if the SQL query loads an collection of basic-typed values.
- Since:
- 6.2
- See Also:
- Implementation Note:
- This annotation is just an abbreviation for
Loader
together withNamedNativeQuery
.
-
Required Element Summary
-
Optional Element Summary
-
Element Details
-
sql
String sqlThe SQLSELECT
statement.
-
-
-
resultSetMapping
SqlResultSetMapping resultSetMapping- Default:
- @jakarta.persistence.SqlResultSetMapping(name="")
-
querySpaces
String[] querySpacesThe query spaces involved in this query.- See Also:
- Default:
- {}
-