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 jakarta.persistence.criteria.Fetch<?,?>>
Ffetch(jakarta.persistence.criteria.From<?, T> from, jakarta.persistence.criteria.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> jakarta.persistence.criteria.Fetch <T, P> fetch(jakarta.persistence.criteria.From<?, T> from, PropertyReference<T, P> property) Create afetch joinusing the givenproperty.static <T,P> jakarta.persistence.criteria.Expression <P> get(jakarta.persistence.criteria.From<?, T> from, TypedPropertyPath<T, P> property) Resolve anExpressionfor the given property path.static <T, J extends jakarta.persistence.criteria.Join<?,?>>
Jjoin(jakarta.persistence.criteria.From<?, T> from, jakarta.persistence.criteria.JoinType joinType, Function<Expressions.Joiner<T>, J> function) Create aJoinconsideringJoinTypeusing the given joiner function allowing to express joins using property references.static <T,P> jakarta.persistence.criteria.Join <T, P> join(jakarta.persistence.criteria.From<?, T> from, PropertyReference<T, P> property) Create aJoinusing the givenproperty.static <T,P> jakarta.persistence.criteria.Path <P> path(jakarta.persistence.criteria.Path<T> from, TypedPropertyPath<T, P> property) Resolve aPathfor the given property path.static <T> List<jakarta.persistence.criteria.Selection<?>> select(jakarta.persistence.criteria.From<?, T> from, TypedPropertyPath<T, ?>... properties) Create a list ofselection objectsfor the given property paths.static <T,P> jakarta.persistence.criteria.Selection <P> select(jakarta.persistence.criteria.From<?, T> from, TypedPropertyPath<T, P> property) Create aSelectionfor the given property path.
-
Method Details
-
path
public static <T,P> jakarta.persistence.criteria.Path<P> path(jakarta.persistence.criteria.Path<T> from, TypedPropertyPath<T, P> property) Resolve aPathfor the given property path.The resulting path can be used in predicates. In case of a
Frompath, Expression resolution navigates joins as necessary.- Parameters:
from- the entity or attribute path start from.property- property path to navigate.- Returns:
- the resolved path.
-
get
public static <T,P> jakarta.persistence.criteria.Expression<P> get(jakarta.persistence.criteria.From<?, T> from, TypedPropertyPath<T, P> property) 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
public static <T,P> jakarta.persistence.criteria.Selection<P> select(jakarta.persistence.criteria.From<?, T> from, TypedPropertyPath<T, P> property) 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<jakarta.persistence.criteria.Selection<?>> select(jakarta.persistence.criteria.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
public static <T,P> jakarta.persistence.criteria.Join<T,P> join(jakarta.persistence.criteria.From<?, T> from, PropertyReference<T, P> property) Create aJoinusing the givenproperty.- 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 jakarta.persistence.criteria.Join<?,?>> J join(jakarta.persistence.criteria.From<?, T> from, jakarta.persistence.criteria.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
public static <T,P> jakarta.persistence.criteria.Fetch<T,P> fetch(jakarta.persistence.criteria.From<?, T> from, PropertyReference<T, P> property) 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 jakarta.persistence.criteria.Fetch<?,?>> F fetch(jakarta.persistence.criteria.From<?, T> from, jakarta.persistence.criteria.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:
-