Interface SimpleProjectionSpecification<T,X>
- Type Parameters:
T
- The result type of theSelectionSpecification
X
- The type of the projected path or attribute
- All Superinterfaces:
QuerySpecification<T>
Allows a
SelectionSpecification
to be augmented with the specification of
a single projected attribute or path.
var specification = SelectionSpecification.create(Book.class) .restrict(Restriction.contains(Book_.title, "hibernate", false)) .sort(Order.desc(Book_.title)); var projection = SimpleProjectionSpecification.create(specification, Book_.isbn); var isbns = projection.createQuery(session).getResultList();
Use of a Path
allows joining to associated entities.
var specification = SelectionSpecification.create(Book.class) .restrict(Restriction.contains(Book_.title, "hibernate", false)) .sort(Order.desc(Book_.title)); var projection = SimpleProjectionSpecification.create(specification, Path.from(Book.class) .to(Book_.publisher) .to(Publisher_.name)); var publisherNames = projection.createQuery(session).getResultList();
- Since:
- 7.2
- API Note:
- This interface marked
Incubating
is considered experimental. Changes to the API defined here are fully expected in future releases.
-
Method Summary
Modifier and TypeMethodDescriptionbuildCriteria
(CriteriaBuilder builder) Build acriteria query
satisfying this specification, using the givenCriteriaBuilder
.static <T,
X> SimpleProjectionSpecification <T, X> create
(SelectionSpecification<T> selectionSpecification, SingularAttribute<? super T, X> projectedAttribute) Create a newProjectionSpecification
which augments the givenSelectionSpecification
.static <T,
X> SimpleProjectionSpecification <T, X> create
(SelectionSpecification<T> selectionSpecification, Path<T, X> projectedPath) 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)
.validate
(CriteriaBuilder builder) Validate the query.Methods inherited from interface org.hibernate.query.specification.QuerySpecification
restrict
-
Method Details
-
create
static <T,X> SimpleProjectionSpecification<T,X> create(SelectionSpecification<T> selectionSpecification, Path<T, X> projectedPath) Create a newProjectionSpecification
which augments the givenSelectionSpecification
. -
create
static <T,X> SimpleProjectionSpecification<T,X> create(SelectionSpecification<T> selectionSpecification, SingularAttribute<? super T, X> projectedAttribute) Create a newProjectionSpecification
which augments the givenSelectionSpecification
. -
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<X> 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
-