Class Expressions
java.lang.Object
org.springframework.data.jpa.criteria.Expressions
Utility methods to resolve JPA Criteria API objects using Spring Data's type-safe property references. These helper
methods obtain Criteria API objects using
TypedPropertyPath and PropertyReference to resolve
property expressions and joins.
The class is intended for concise, type-aware criteria construction through a type-safe DSL where property references are preferred over string-based navigation.
Example:
Root<User> root = criteriaQuery.from(User.class); Expression<User> expr = Expressions.get(root, User::getManager); Join<User, Address> join = Expressions.join(root, JoinType.INNER, j -> j.join(User::getAddress));
- Since:
- 4.1
- Author:
- Mark Paluch
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceStrategy interface used byfetch(From, PropertyReference)to obtain fetch joins using property references.static interfaceStrategy interface used byjoin(From, PropertyReference)to obtain joins using property references. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T, F extends Fetch<?,?>>
Ffetch(From<?, T> from, JoinType joinType, Function<Expressions.Fetcher<T>, F> function) Create afetch joinconsideringJoinTypeusing the given fetcher function allowing to express fetches using property references.static <T,P> Fetch <T, P> fetch(From<?, T> from, PropertyReference<T, P> property) Create afetch joinusing the givenproperty.static <T,P> Expression <P> get(From<?, T> from, TypedPropertyPath<T, P> property) Resolve anExpressionfor the given property path.static <T, J extends Join<?,?>>
Jjoin(From<?, T> from, JoinType joinType, Function<Expressions.Joiner<T>, J> function) static <T,P> Join <T, P> join(From<?, T> from, PropertyReference<T, P> property) static <T,P> Path <P> path(Path<T> from, TypedPropertyPath<T, P> property) Resolve aPathfor the given property path.select(From<?, T> from, TypedPropertyPath<T, ?>... properties) Create a list ofselection objectsfor the given property paths.static <T,P> Selection <P> select(From<?, T> from, TypedPropertyPath<T, P> property) Create aSelectionfor the given property path.
-
Method Details
-
path
-
get
Resolve anExpressionfor the given property path.The resulting expression can be used in predicates. Expression resolution navigates joins as necessary.
- Parameters:
from- the root or join to start from.property- property path to navigate.- Returns:
- the resolved expression.
-
select
Create aSelectionfor the given property path.The resulting object can be used in the selection, joined paths consider outer joins as needed.
- Parameters:
from- the root or join to start from.property- property path to navigate.- Returns:
- the selection.
-
select
@SafeVarargs public static <T> List<Selection<?>> select(From<?, T> from, TypedPropertyPath<T, ?>... properties) Create a list ofselection objectsfor the given property paths.The resulting objects can be used in the selection, joined paths consider outer joins as needed.
- Parameters:
from- the root or join to start from.properties- property path to navigate.- Returns:
- the selection.
-
join
- Parameters:
from- the root or join to start from.property- property reference to navigate.- Returns:
- the resolved join.
- See Also:
-
join
public static <T, J extends Join<?,?>> J join(From<?, T> from, JoinType joinType, Function<Expressions.Joiner<T>, J> function) Create aJoinconsideringJoinTypeusing the given joiner function allowing to express joins using property references.- Parameters:
from- the root or join to start from.joinType- the join type.function- joiner function.- Returns:
- the resolved join.
- See Also:
-
fetch
Create afetch joinusing the givenproperty.- Parameters:
from- the root or join to start from.property- property reference to navigate.- Returns:
- the resolved fetch.
- See Also:
-
fetch
public static <T, F extends Fetch<?,?>> F fetch(From<?, T> from, JoinType joinType, Function<Expressions.Fetcher<T>, F> function) Create afetch joinconsideringJoinTypeusing the given fetcher function allowing to express fetches using property references.- Parameters:
from- the root or join to start from.joinType- the join type.function- fetcher function.- Returns:
- the resolved fetch.
- See Also:
-