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
Incubatingis considered experimental. Changes to the API defined here are fully expected in future releases.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAllows typesafe access to elements of theObject[]arrays returned by the query. -
Method Summary
Modifier and TypeMethodDescriptionbuildCriteria(CriteriaBuilder builder) Build acriteria querysatisfying this specification, using the givenCriteriaBuilder.static <T> ProjectionSpecification<T> create(SelectionSpecification<T> selectionSpecification) Create a newProjectionSpecificationwhich 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 QuerySpecification
restrict
-
Method Details
-
create
Create a newProjectionSpecificationwhich augments the givenSelectionSpecification. -
select
Select the given attribute of the root entity.- Parameters:
attribute- An attribute of the root entity- Returns:
- An
ProjectionSpecification.Elementallowing 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.Elementallowing typesafe access to the results
-
createQuery
Description copied from interface:QuerySpecificationFinalize the building and create executable query instance.- Specified by:
createQueryin interfaceQuerySpecification<T>
-
createQuery
Description copied from interface:QuerySpecificationFinalize the building and create executable query instance.- Specified by:
createQueryin interfaceQuerySpecification<T>
-
createQuery
Description copied from interface:QuerySpecificationFinalize the building and create executable query instance.- Specified by:
createQueryin interfaceQuerySpecification<T>
-
buildCriteria
Description copied from interface:QuerySpecificationBuild acriteria querysatisfying this specification, using the givenCriteriaBuilder.If the returned criteria query is mutated, the mutations will not be not reflected in this specification.
- Specified by:
buildCriteriain interfaceQuerySpecification<T>- Returns:
- a new criteria query
-
reference
TypedQueryReference<Object[]> reference()Description copied from interface:QuerySpecificationObtain a reference to this specification which may be passed along toEntityManager.createQuery(TypedQueryReference).- Specified by:
referencein interfaceQuerySpecification<T>
-
validate
Description copied from interface:QuerySpecificationValidate the query.- Specified by:
validatein interfaceQuerySpecification<T>- Returns:
thisif everything is fine
-