diff --git a/persistence-modules/spring-data-jpa-query-2/README.md b/persistence-modules/spring-data-jpa-query-2/README.md new file mode 100644 index 0000000000..a4d657d4c6 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query-2/README.md @@ -0,0 +1,16 @@ +## Spring Data JPA - Query + +This module contains articles about querying data using Spring Data JPA + +### Relevant Articles: +- [Use Criteria Queries in a Spring Data Application](https://www.baeldung.com/spring-data-criteria-queries) +- More articles: [[<-- prev]](../spring-data-jpa-query) + +### Eclipse Config +After importing the project into Eclipse, you may see the following error: +"No persistence xml file found in project" + +This can be ignored: +- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" +Or: +- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator diff --git a/persistence-modules/spring-data-jpa-query-2/pom.xml b/persistence-modules/spring-data-jpa-query-2/pom.xml new file mode 100644 index 0000000000..b9e5120543 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query-2/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + spring-data-jpa-query + spring-data-jpa-query-2 + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + com.h2database + h2 + + + + com.fasterxml.jackson.core + jackson-databind + + + + \ No newline at end of file diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookRepository.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookRepository.java similarity index 100% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookRepository.java rename to persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookRepository.java diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookRepositoryCustom.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookRepositoryCustom.java similarity index 100% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookRepositoryCustom.java rename to persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookRepositoryCustom.java index 1b46d0ecc3..eda34542df 100644 --- a/persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookRepositoryCustom.java +++ b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookRepositoryCustom.java @@ -1,9 +1,9 @@ package com.baeldung.persistence.dao; -import java.util.List; - import com.baeldung.persistence.model.Book; +import java.util.List; + public interface BookRepositoryCustom { List findBooksByAuthorNameAndTitle(String authorName, String title); diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookRepositoryImpl.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookRepositoryImpl.java similarity index 99% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookRepositoryImpl.java rename to persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookRepositoryImpl.java index 241a4c05aa..7f5bedd018 100644 --- a/persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookRepositoryImpl.java +++ b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookRepositoryImpl.java @@ -1,7 +1,7 @@ package com.baeldung.persistence.dao; -import java.util.ArrayList; -import java.util.List; +import com.baeldung.persistence.model.Book; +import org.springframework.stereotype.Repository; import javax.persistence.EntityManager; import javax.persistence.TypedQuery; @@ -9,9 +9,8 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; - -import com.baeldung.persistence.model.Book; -import org.springframework.stereotype.Repository; +import java.util.ArrayList; +import java.util.List; @Repository public class BookRepositoryImpl implements BookRepositoryCustom { diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookService.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookService.java similarity index 90% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookService.java rename to persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookService.java index f02f9daa11..4165cd8eb9 100644 --- a/persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookService.java +++ b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookService.java @@ -1,14 +1,14 @@ package com.baeldung.persistence.dao; -import static com.baeldung.persistence.dao.BookSpecifications.hasAuthor; -import static com.baeldung.persistence.dao.BookSpecifications.titleContains; -import static org.springframework.data.jpa.domain.Specifications.where; - -import java.util.List; - import com.baeldung.persistence.model.Book; import org.springframework.stereotype.Service; +import java.util.List; + +import static com.baeldung.persistence.dao.BookSpecifications.hasAuthor; +import static com.baeldung.persistence.dao.BookSpecifications.titleContains; +import static org.springframework.data.jpa.domain.Specification.where; + @Service public class BookService { diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookSpecifications.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookSpecifications.java similarity index 100% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/dao/BookSpecifications.java rename to persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/dao/BookSpecifications.java diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/model/Book.java b/persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/model/Book.java similarity index 100% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/persistence/model/Book.java rename to persistence-modules/spring-data-jpa-query-2/src/main/java/com/baeldung/persistence/model/Book.java diff --git a/persistence-modules/spring-data-jpa-query/README.md b/persistence-modules/spring-data-jpa-query/README.md index bfff3c0ef3..34e397394b 100644 --- a/persistence-modules/spring-data-jpa-query/README.md +++ b/persistence-modules/spring-data-jpa-query/README.md @@ -11,6 +11,7 @@ This module contains articles about querying data using Spring Data JPA - [Spring Data JPA Query by Example](https://www.baeldung.com/spring-data-query-by-example) - [JPA Join Types](https://www.baeldung.com/jpa-join-types) - [Spring Data JPA and Named Entity Graphs](https://www.baeldung.com/spring-data-jpa-named-entity-graphs) +- More articles: [[more -->]](../spring-data-jpa-query-2) ### Eclipse Config After importing the project into Eclipse, you may see the following error: diff --git a/persistence-modules/spring-jpa/README.md b/persistence-modules/spring-jpa/README.md index d260913635..f60609e0de 100644 --- a/persistence-modules/spring-jpa/README.md +++ b/persistence-modules/spring-jpa/README.md @@ -7,7 +7,6 @@ - [Self-Contained Testing Using an In-Memory Database](https://www.baeldung.com/spring-jpa-test-in-memory-database) - [A Guide to Spring AbstractRoutingDatasource](https://www.baeldung.com/spring-abstract-routing-data-source) - [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys) -- [Use Criteria Queries in a Spring Data Application](https://www.baeldung.com/spring-data-criteria-queries) - More articles: [[next -->]](/spring-jpa-2) ### Eclipse Config