spring-projects / spring-projects/spring-data-rest
Custom queries throw exceptions [DATAREST-878]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- 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:
- CustomQueryException-ConversionFailedException.txt (10.95 kB)
- CustomQueryException-NPE.txt (9.55 kB)
- server-debug.zip (601.00 kB)
3 votes, 2 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.