eugenp / tutorials

Just Announced - "Learn Spring Security OAuth":
http://bit.ly/github-lsso
MIT License
36.61k stars 54.48k forks source link

[ISSUE] spring-data-jpa-simple has failing test #17777

Open simbo1905 opened 1 week ago

simbo1905 commented 1 week ago

The article Introduction to Spring Data JPA which links to the code persistence-modules/spring-data-jpa-simple has a runtime bug.

Describe the Issue

Running all the tests has one failure for JpaProjectionIntegrationTest which is:

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
[2024-10-08 05:36:57,830]-[main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personRepository' defined in com.baeldung.jpa.projection.repository.PersonRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract com.baeldung.jpa.projection.view.PersonDto com.baeldung.jpa.projection.repository.PersonRepository.findByFirstName(java.lang.String); Reason: Failed to create query for method public abstract com.baeldung.jpa.projection.view.PersonDto com.baeldung.jpa.projection.repository.PersonRepository.findByFirstName(java.lang.String); Source must not be null or empty

To Reproduce

Steps to reproduce the behavior:

mvn -Dpmd.skip=true -Dtest=JpaProjectionIntegrationTest test

Expected Behavior

The test should pass.

Environment (please complete the following information):

mvn --version
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: /usr/local/Cellar/maven/3.9.9/libexec
Java version: 23, vendor: GraalVM Community, runtime: /Users/consensussolutions/.sdkman/candidates/java/23-graalce
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "15.0.1", arch: "x86_64", family: "mac"
simbo1905 commented 1 week ago

If i add the following @Query annotation:

@Query("SELECT new com.baeldung.jpa.projection.view.PersonDto(p.firstName, p.lastName) FROM Person p WHERE p.firstName = :firstName")
    PersonDto findByFirstName(@Param("firstName") String firstName);

Then four out of the five failing test methods pass.