Interface ProjectionSpecification<T>
- Type Parameters:
T
- The result type of theSelectionSpecification
- All Superinterfaces:
QuerySpecification<Object[]>
Allows a
SelectionSpecification
to be augmented with the specification
of a projection list.
var specification = SelectionSpecification.create(Book.class) .restrict(Restriction.contains(Book_.title, "hibernate", false)) .sort(Order.desc(Book_.title)); var projection = ProjectionSpecification.create(specification); var bookIsbn = projection.select(Book_.isbn); var bookTitle = projection.select(Book_.title); var results = projection.createQuery(session).getResultList(); for (var result : results) { var isbn = bookIsbn.in(result); var title = bookTitle.in(result); ... }
A ProjectionSpecification
always results in a query which with result
type Object[]
. The select()
methods
return ProjectionSpecification.Element
, allowing easy and typesafe access to the elements of
the returned array.
- Since:
- 7.2
- API Note:
- This interface marked
Incubating
is considered experimental. Changes to the API defined here are fully expected in future releases.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Allows typesafe access to elements of theObject[]
arrays returned by the query. -
Method Summary
Modifier and TypeMethodDescriptionbuildCriteria
(CriteriaBuilder builder) Build acriteria query
satisfying this specification, using the givenCriteriaBuilder
.static <T> ProjectionSpecification
<T> create
(SelectionSpecification<T> selectionSpecification) Create a newProjectionSpecification
which augments the givenSelectionSpecification
.createQuery
(EntityManager entityManager) Finalize the building and create executable query instance.createQuery
(Session session) Finalize the building and create executable query instance.createQuery
(StatelessSession session) Finalize the building and create executable query instance.Obtain a reference to this specification which may be passed along toEntityManager.createQuery(TypedQueryReference)
.select
(SingularAttribute<T, X> attribute) Select the given attribute of the root entity.Select the given field or property identified by the given path from of the root entity.validate
(CriteriaBuilder builder) Validate the query.Methods inherited from interface org.hibernate.query.specification.QuerySpecification
restrict
-
Method Details
-
create
Create a newProjectionSpecification
which augments the givenSelectionSpecification
. -
select
Select the given attribute of the root entity.- Parameters:
attribute
- An attribute of the root entity- Returns:
- An
ProjectionSpecification.Element
allowing typesafe access to the results
-
select
Select the given field or property identified by the given path from of the root entity.- Parameters:
path
- A path from the root entity- Returns:
- An
ProjectionSpecification.Element
allowing typesafe access to the results
-
createQuery
Description copied from interface:QuerySpecification
Finalize the building and create executable query instance.- Specified by:
createQuery
in interfaceQuerySpecification<T>
-
createQuery
Description copied from interface:QuerySpecification
Finalize the building and create executable query instance.- Specified by:
createQuery
in interfaceQuerySpecification<T>
-
createQuery
Description copied from interface:QuerySpecification
Finalize the building and create executable query instance.- Specified by:
createQuery
in interfaceQuerySpecification<T>
-
buildCriteria
Description copied from interface:QuerySpecification
Build acriteria query
satisfying this specification, using the givenCriteriaBuilder
.If the returned criteria query is mutated, the mutations will not be not reflected in this specification.
- Specified by:
buildCriteria
in interfaceQuerySpecification<T>
- Returns:
- a new criteria query
-
reference
TypedQueryReference<Object[]> reference()Description copied from interface:QuerySpecification
Obtain a reference to this specification which may be passed along toEntityManager.createQuery(TypedQueryReference)
.- Specified by:
reference
in interfaceQuerySpecification<T>
-
validate
Description copied from interface:QuerySpecification
Validate the query.- Specified by:
validate
in interfaceQuerySpecification<T>
- Returns:
this
if everything is fine
-