Skip to content

Backport Specification.unrestricted() #3940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
33d532b
Prepare next development iteration.
mp911de May 16, 2025
42463ae
After release cleanups.
mp911de May 16, 2025
a9813a7
Document deprecation of `Specification.where(…)`.
mp911de May 19, 2025
fa9b681
Avoid capturing `?&` and `?|` as bind parameter markers.
mp911de Jun 3, 2025
c538a4f
Refrain from rewriting queries without input properties.
mp911de Jun 2, 2025
64d5e70
Do not consider JPA-managed types projections.
mp911de Jun 2, 2025
61a1a8c
Fix potential class-cast exception.
mp911de Jun 3, 2025
5a22fbf
Refine DTO projection rewriting.
mp911de Jun 3, 2025
053a462
Consider only top-level properties for tuple query selection.
mp911de Jun 4, 2025
15e4096
Suppress warnings in tests.
May 27, 2025
4838fa1
Polishing.
mp911de Jun 4, 2025
71ef321
Upgrade to Hibernate 6.6.17.Final.
mp911de Jun 5, 2025
c8221aa
Prevent access to `EntityManager` when looking up `PersistenceProvider`.
mp911de Jun 5, 2025
5bd9440
Polishing.
mp911de Jun 5, 2025
c260c21
Fix `QueryUtils` regex parsing field and function aliases.
mp911de Jun 10, 2025
72f6627
Polishing.
mp911de Jun 10, 2025
a54ad17
Upgrade to PGJDBC Driver 42.7.7.
mp911de Jun 11, 2025
b7b9db5
Fix typos in query-methods.adoc.
hoyeonj981 Jun 7, 2025
261d693
Polishing.
mp911de Jun 12, 2025
01a2c72
Prepare 3.5.1 (2025.0.1).
mp911de Jun 13, 2025
bb662ae
Release version 3.5.1 (2025.0.1).
mp911de Jun 13, 2025
f3c93ef
Prepare next development iteration.
mp911de Jun 13, 2025
961d825
After release cleanups.
mp911de Jun 13, 2025
faa526f
Polishing.
mp911de Jun 17, 2025
2489e01
Fix `PersistenceProvider` lookup using proxied `EntityManagerFactory`.
mp911de Jun 25, 2025
ab96acc
Simplify build.
mp911de Jun 26, 2025
caa4704
Exclude DTO types without custom construction from DTO constructor re…
mp911de Jul 7, 2025
f92b40c
Replace regex with startsWith / endsWith check for LIKE pattern detec…
Dockerel Jul 9, 2025
f635de7
Polishing.
mp911de Jul 10, 2025
a4fe9c3
Cache query strings in `SimpleJpaRepository`.
Dockerel Jun 15, 2025
3784582
Polishing.
mp911de Jul 10, 2025
672ab08
Upgrade to Eclipselink 4.0.7.
mp911de Jul 14, 2025
0e39197
Upgrade to Hibernate 6.6.21.Final.
mp911de Jul 14, 2025
7d28b21
Backport Specification.unrestricted() from main branch.
r-gruber Jul 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pipeline {

triggers {
pollSCM 'H/10 * * * *'
upstream(upstreamProjects: "spring-data-commons/main", threshold: hudson.model.Result.SUCCESS)
upstream(upstreamProjects: "spring-data-commons/3.5.x", threshold: hudson.model.Result.SUCCESS)
}

options {
Expand Down Expand Up @@ -124,28 +124,6 @@ pipeline {
}
}
}
stage("test: eclipselink-next") {
agent {
label 'data'
}
options { timeout(time: 30, unit: 'MINUTES')}
environment {
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
DEVELOCITY_ACCESS_KEY = credentials("${p['develocity.access-key']}")
TESTCONTAINERS_IMAGE_SUBSTITUTOR = 'org.springframework.data.jpa.support.ProxyImageNameSubstitutor'
}
steps {
script {
docker.withRegistry(p['docker.proxy.registry'], p['docker.proxy.credentials']) {
docker.image(p['docker.java.main.image']).inside(p['docker.java.inside.docker']) {
sh "PROFILE=all-dbs,eclipselink-next " +
"JENKINS_USER_NAME=${p['jenkins.user.name']} " +
"ci/test.sh"
}
}
}
}
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Spring Data JPA image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-jpa%2Fmain&subject=Build[link=https://jenkins.spring.io/view/SpringData/job/spring-data-jpa/] image:https://img.shields.io/badge/Revved%20up%20by-Develocity-06A0CE?logo=Gradle&labelColor=02303A["Revved up by Develocity", link="https://ge.spring.io/scans?search.rootProjectNames=Spring Data JPA Parent"]
= Spring Data JPA image:https://img.shields.io/badge/Revved%20up%20by-Develocity-06A0CE?logo=Gradle&labelColor=02303A["Revved up by Develocity", link="https://ge.spring.io/scans?search.rootProjectNames=Spring Data JPA Parent"]

Spring Data JPA, part of the larger https://projects.spring.io/spring-data[Spring Data] family, makes it easy to implement JPA-based repositories.
This module deals with enhanced support for JPA-based data access layers.
Expand Down Expand Up @@ -157,7 +157,9 @@ You also need JDK 17 or above.

If you want to build with the regular `mvn` command, you will need https://maven.apache.org/run-maven/index.html[Maven v3.8.0 or above].

_Also see link:CONTRIBUTING.adoc[CONTRIBUTING.adoc] if you wish to submit pull requests, and in particular please sign the https://cla.pivotal.io/sign/spring[Contributor’s Agreement] before your first non-trivial change._
_Also see link:CONTRIBUTING.adoc[CONTRIBUTING.adoc] if you wish to submit pull requests._
All commits must include a __Signed-off-by__ trailer at the end of each commit message to indicate that the contributor agrees to the Developer Certificate of Origin.
For additional details, please refer to the blog post https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring[Hello DCO, Goodbye CLA: Simplifying Contributions to Spring].

=== Building reference documentation

Expand All @@ -168,7 +170,7 @@ Building the documentation builds also the project without running tests.
$ ./mvnw clean install -Pantora
----

The generated documentation is available from `target/antora/site/index.html`.
The generated documentation is available from `target/antora/index.html`.

== Guides

Expand Down
34 changes: 23 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.5.0</version>
<version>3.5.2-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data JPA Parent</name>
Expand All @@ -23,25 +23,25 @@
<parent>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-parent</artifactId>
<version>3.5.0</version>
<version>3.5.2-SNAPSHOT</version>
</parent>

<properties>
<antlr>4.13.0</antlr> <!-- align with Hibernate's parser -->
<eclipselink>4.0.6</eclipselink>
<eclipselink-next>4.0.7-SNAPSHOT</eclipselink-next>
<hibernate>6.6.15.Final</hibernate>
<hibernate-62>6.2.36.Final</hibernate-62>
<hibernate-66-snapshots>6.6.16-SNAPSHOT</hibernate-66-snapshots>
<eclipselink>4.0.7</eclipselink>
<eclipselink-next>4.0.8-SNAPSHOT</eclipselink-next>
<hibernate>6.6.21.Final</hibernate>
<hibernate-62>6.2.38.Final</hibernate-62>
<hibernate-66-snapshots>6.6.22-SNAPSHOT</hibernate-66-snapshots>
<hibernate-70>7.0.0.Beta5</hibernate-70>
<hibernate-70-snapshots>7.0.0-SNAPSHOT</hibernate-70-snapshots>
<hsqldb>2.7.4</hsqldb>
<h2>2.3.232</h2>
<jakarta-persistence-api>3.1.0</jakarta-persistence-api>
<jsqlparser>5.2</jsqlparser>
<mysql-connector-java>9.2.0</mysql-connector-java>
<postgresql>42.7.5</postgresql>
<springdata.commons>3.5.0</springdata.commons>
<postgresql>42.7.7</postgresql>
<springdata.commons>3.5.2-SNAPSHOT</springdata.commons>
<vavr>0.10.3</vavr>

<hibernate.groupId>org.hibernate</hibernate.groupId>
Expand Down Expand Up @@ -173,8 +173,20 @@
</build>

<repositories>


<repository>
<id>spring-snapshot</id>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>spring-milestone</id>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>

<pluginRepositories>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-envers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
<version>3.5.0</version>
<version>3.5.2-SNAPSHOT</version>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.5.0</version>
<version>3.5.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-jpa-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.5.0</version>
<version>3.5.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>3.5.0</version>
<version>3.5.2-SNAPSHOT</version>

<name>Spring Data JPA</name>
<description>Spring Data module for JPA repositories.</description>
Expand All @@ -16,7 +16,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>3.5.0</version>
<version>3.5.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@ public interface Specification<T> extends Serializable {

@Serial long serialVersionUID = 1L;

/**
* Simple static factory method to create a specification matching all objects.
*
* @param <T> the type of the {@link Root} the resulting {@literal Specification} operates on.
* @return guaranteed to be not {@literal null}.
*/
static <T> Specification<T> unrestricted() {
return (root, query, builder) -> null;
}

/**
* Negates the given {@link Specification}.
*
* @apiNote with 4.0, this method will no longer accept {@literal null} specifications.
* @param <T> the type of the {@link Root} the resulting {@literal Specification} operates on.
* @param spec can be {@literal null}.
* @return guaranteed to be not {@literal null}.
Expand All @@ -58,19 +69,21 @@ static <T> Specification<T> not(@Nullable Specification<T> spec) {
? (root, query, builder) -> null //
: (root, query, builder) -> {

Predicate predicate = spec.toPredicate(root, query, builder);
Predicate predicate = spec.toPredicate(root, query, builder);
return predicate != null ? builder.not(predicate) : builder.disjunction();
};
};
}

/**
* Simple static factory method to add some syntactic sugar around a {@link Specification}.
*
* @apiNote with 4.0, this method will no longer accept {@literal null} specifications.
* @param <T> the type of the {@link Root} the resulting {@literal Specification} operates on.
* @param spec can be {@literal null}.
* @return guaranteed to be not {@literal null}.
* @since 2.0
* @deprecated since 3.5.
* @deprecated since 3.5, to be removed with 4.0 as we no longer want to support {@literal null} specifications. Use
* {@link #unrestricted()} instead.
*/
@Deprecated(since = "3.5.0", forRemoval = true)
static <T> Specification<T> where(@Nullable Specification<T> spec) {
Expand All @@ -80,6 +93,7 @@ static <T> Specification<T> where(@Nullable Specification<T> spec) {
/**
* ANDs the given {@link Specification} to the current one.
*
* @apiNote with 4.0, this method will no longer accept {@literal null} specifications.
* @param other can be {@literal null}.
* @return The conjunction of the specifications
* @since 2.0
Expand All @@ -91,6 +105,7 @@ default Specification<T> and(@Nullable Specification<T> other) {
/**
* ORs the given specification to the current one.
*
* @apiNote with 4.0, this method will no longer accept {@literal null} specifications.
* @param other can be {@literal null}.
* @return The disjunction of the specifications
* @since 2.0
Expand All @@ -104,7 +119,9 @@ default Specification<T> or(@Nullable Specification<T> other) {
* {@link Root} and {@link CriteriaQuery}.
*
* @param root must not be {@literal null}.
* @param query can be {@literal null} to allow overrides that accept {@link jakarta.persistence.criteria.CriteriaDelete} which is an {@link jakarta.persistence.criteria.AbstractQuery} but no {@link CriteriaQuery}.
* @param query can be {@literal null} to allow overrides that accept
* {@link jakarta.persistence.criteria.CriteriaDelete} which is an
* {@link jakarta.persistence.criteria.AbstractQuery} but no {@link CriteriaQuery}.
* @param criteriaBuilder must not be {@literal null}.
* @return a {@link Predicate}, may be {@literal null}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static boolean isMetamodelOfType(Metamodel metamodel, String type) {
return isOfType(metamodel, type, metamodel.getClass().getClassLoader());
}

private static boolean isOfType(Object source, String typeName, @Nullable ClassLoader classLoader) {
static boolean isOfType(Object source, String typeName, @Nullable ClassLoader classLoader) {

Assert.notNull(source, "Source instance must not be null");
Assert.hasText(typeName, "Target type name must not be null or empty");
Expand Down
Loading