spring-projects / spring-projects/spring-data-rest

Custom queries throw exceptions [DATAREST-878]

Open
#1,248 5 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

status: feedback-provided type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

John Hall opened DATAREST-878 and commented

When I originally pitched SDR to my team, basic "findBy..." queries worked just fine, but now that the application has become a little more complex these queries have started throwing exceptions, which is a showstopper for my team. The basic findAll() and findOne() queries work fine, but any other custom query throws exceptions. It doesn't matter if it's written using the naming conventions (e.g. findByNameLike) or an @Query annotations, they still fail. The custom query that I'm using to create the exceptions is really basic:

@RepositoryRestResource(collectionResourceRel = "org", path = "org")
public interface OrganizationRepository extends CrudRepository<Organization, Long> {

    Set<Organization> findByNameLike(@Param("name") String name);

}

Interestingly, I can generate 2 different exceptions here - running the query with the repo written as above will generate the attached ConversionFailedException. However, if you just remove (collectionResourceRel = "org", path = "org"), then it generates the attached NullPointerException.

In the case of the ConversionFailedException, I stepped through the SDR code and what I found is that SDR is attempting to invoke the default findOne() method using the name of the custom query function ("findByNameLike") as the id and then it fails because it's trying to convert that string into a long.

Our application dependencies are still fairly simple; we're using Spring Boot 1.4.0:

dependencies {
    compile project(':common')
    compile('org.springframework.boot:spring-boot-starter-data-rest') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
    }
    compile 'org.springframework.boot:spring-boot-starter-data-jpa',
            'org.springframework.boot:spring-boot-starter-data-solr'

    providedCompile 'javax.servlet:javax.servlet-api:3.1.0'

    runtime('org.hibernate:hibernate-spatial:5.2.2.Final') {
        exclude group: 'postgresql', module: 'postgresql'
    }
    runtime 'ojdbc:ojdbc14:10.2.0.5',
            'org.hibernate:hibernate-ehcache',
            'org.hibernate:hibernate-envers'
}

The dependencies in the common sub-project are also simple:

dependencies {
    compile('org.springframework.boot:spring-boot-starter-thymeleaf') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
    }
    compile 'org.springframework.boot:spring-boot-starter-mail',
            'org.apache.commons:commons-lang3:3.4'
}

I'm happy to provide as much debug information as you need


Affects: 2.5.2 (Hopper SR2)

Attachments:

3 votes, 2 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.