Interface StatementReference
- All Superinterfaces:
Reference
- All Known Implementing Classes:
StaticStatementReference
NamedQuery or NamedNativeQuery annotations,
or using JakartaQuery or
NativeQuery. An
instance of StatementReference is usually obtained
from the static metamodel of the annotated type.
In this example, a method is annotated, and the name of the statement is determined by the name of the annotated method:
class Filer {
@Inject EntityManager entityManager;
@JakartaQuery("delete from Record where temporary = true")
int purgeTemporaryRecords() {
return entityManager.createStatement(Filer_.purgeTemporaryRecords())
.execute();
}
}
In this example, the entity class is annotated,
and the NamedQuery annotation explicitly specifies a
name:
@NamedQuery(name = "updateSales",
query = "update Book set sales = ?1 where isbn = ?2")
@Entity class Book { .. }
In this case the StatementReference obtained from
its static metamodel does not include arguments to the query
parameters, and so they must be supplied via setParameter:
int updated =
entityManager.createStatement(Book_._updateSales_)
.setParameter(1, sales)
.setParameter(2, isbn)
.execute();
A StatementReference may include arguments to parameters
of the query.
- A reference representing a query declared using an
annotation of a type or field has no arguments, and so
Reference.getArguments(),Reference.getParameterNames(), andReference.getParameterTypes()all returnnull. - A reference representing a query declared using an
annotation of a method holds information about the
arguments passed to the method, making it available via
Reference.getArguments(),Reference.getParameterNames(), andReference.getParameterTypes().
In the Jakarta Persistence query language, a DELETE or
UPDATE statement is not a typed query and is always
represented by an instance of StatementReference.
A native SQL query is represented by an instance of
StatementReference if it returns a row count. A
Jakarta Persistence SELECT query, or a native SQL query
that returns a result set, is usually represented as an
instance of TypedQueryReference.
- Since:
- 4.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAll options specified byQueryOptions,NamedQuery, orNamedNativeQuery, or an empty set if no options were specified.Methods inherited from interface Reference
getArguments, getHints, getName, getParameterNames, getParameterTypes
-
Method Details
-
getOptions
All options specified byQueryOptions,NamedQuery, orNamedNativeQuery, or an empty set if no options were specified.- See Also:
-