-
@Repeatable(NamedNativeQueries.class) @Target(TYPE) @Retention(RUNTIME) public @interface NamedNativeQuery
Declares a named native SQL query and, optionally, the mapping of the result of the native SQL query. Query names are scoped to the persistence unit. A named query may be executed by callingEntityManager.createNamedQuery(String, Class)
.In simple cases, a
resultClass()
specifies how the native SQL query result set should be interpreted, for example: {@snippet :- Since:
- 1.0
- See Also:
SqlResultSetMapping
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.String
name
The name used to identify the query in calls toEntityManager.createNamedQuery(java.lang.String)
.java.lang.String
query
The native SQL query string.
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description ConstructorResult[]
classes
Specifies the result set mapping to constructors.ColumnResult[]
columns
Specifies the result set mapping to scalar values.EntityResult[]
entities
Specifies the result set mapping to entities.QueryHint[]
hints
Query properties and hints.java.lang.Class<?>
resultClass
The class of each query result.java.lang.String
resultSetMapping
The name of aSqlResultSetMapping
, as defined in metadata.
-
-
-
Element Detail
-
name
java.lang.String name
The name used to identify the query in calls toEntityManager.createNamedQuery(java.lang.String)
.
-
-
-
hints
QueryHint[] hints
Query properties and hints. (May include vendor-specific query hints.)- Default:
- {}
-
-
-
resultClass
java.lang.Class<?> resultClass
The class of each query result. If aresult set mapping
is specified, the specified result class must agree with the type inferred from the result set mapping. If aresultClass
is not explicitly specified, then it is inferred from the result set mapping, if any, or defaults toObject
orObject[]
. The query result class may be overridden by explicitly passing a class object toEntityManager.createNamedQuery(String, Class)
.- Default:
- void.class
-
-
-
resultSetMapping
java.lang.String resultSetMapping
The name of aSqlResultSetMapping
, as defined in metadata. The named result set mapping is used to interpret the result set of the native SQL query.Alternatively, the elements
entities()
,classes()
, andcolumns()
may be used to specify a result set mapping. These elements may not be used in conjunction withresultSetMapping
.- Default:
- ""
-
-
-
entities
EntityResult[] entities
Specifies the result set mapping to entities. May not be used in combination withresultSetMapping()
.- Since:
- 3.2
- Default:
- {}
-
-
-
classes
ConstructorResult[] classes
Specifies the result set mapping to constructors. May not be used in combination withresultSetMapping()
.- Since:
- 3.2
- Default:
- {}
-
-
-
columns
ColumnResult[] columns
Specifies the result set mapping to scalar values. May not be used in combination withresultSetMapping()
.- Since:
- 3.2
- Default:
- {}
-
-