Merge pull request #9896 from kwoyke/JAVA-2305

JAVA-2305: Move Use Criteria Queries in a Spring Data Application to spring-data-jpa-query-2
This commit is contained in:
Loredana Crusoveanu 2020-08-19 13:34:13 +03:00 committed by GitHub
commit af4e2397ea
10 changed files with 62 additions and 14 deletions

View File

@ -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

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-data-jpa-query</artifactId>
<name>spring-data-jpa-query-2</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,9 +1,9 @@
package com.baeldung.persistence.dao; package com.baeldung.persistence.dao;
import java.util.List;
import com.baeldung.persistence.model.Book; import com.baeldung.persistence.model.Book;
import java.util.List;
public interface BookRepositoryCustom { public interface BookRepositoryCustom {
List<Book> findBooksByAuthorNameAndTitle(String authorName, String title); List<Book> findBooksByAuthorNameAndTitle(String authorName, String title);

View File

@ -1,7 +1,7 @@
package com.baeldung.persistence.dao; package com.baeldung.persistence.dao;
import java.util.ArrayList; import com.baeldung.persistence.model.Book;
import java.util.List; import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
@ -9,9 +9,8 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import java.util.ArrayList;
import com.baeldung.persistence.model.Book; import java.util.List;
import org.springframework.stereotype.Repository;
@Repository @Repository
public class BookRepositoryImpl implements BookRepositoryCustom { public class BookRepositoryImpl implements BookRepositoryCustom {

View File

@ -1,14 +1,14 @@
package com.baeldung.persistence.dao; 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 com.baeldung.persistence.model.Book;
import org.springframework.stereotype.Service; 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 @Service
public class BookService { public class BookService {

View File

@ -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) - [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) - [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) - [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 ### Eclipse Config
After importing the project into Eclipse, you may see the following error: After importing the project into Eclipse, you may see the following error:

View File

@ -7,7 +7,6 @@
- [Self-Contained Testing Using an In-Memory Database](https://www.baeldung.com/spring-jpa-test-in-memory-database) - [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) - [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) - [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) - More articles: [[next -->]](/spring-jpa-2)
### Eclipse Config ### Eclipse Config