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

RepositoryNotFoundException thrown in the method objectToMapKey for java.lang.Long [DATAREST-148]

Open
#536 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

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

Description

Thomas Darimont opened DATAREST-148 and commented

Github Author: ocruz
Github Last-Updated: 2013-02-06T21:31:35Z
This issue was automatically imported from github

Retrieving a map resource of a class repository where the key of the map is of type Long, it fails due to a RepositoryNotFoundException that is thrown in the method objectToMapKey. The following piece of code is always throwing the exception looking for a repository for the class java.lang.Long:

java
protected RepositoryMetadata repositoryMetadataFor(Class<?> domainType) {
  for(RepositoryExporter exporter : repositoryExporters) {
    RepositoryMetadata repoMeta = exporter.repositoryMetadataFor(domainType);
    if(null != repoMeta) {
      return repoMeta;
    }
  }
  throw new RepositoryNotFoundException("No repository found for type " + domainType.getName());
}

This method is called in the objectToMapKey method of RestController:

java
if(ClassUtils.isAssignable(obj.getClass(), String.class)) {
     key = (String)obj;
   } else if(null != (repoMeta = repositoryMetadataFor(obj.getClass()))) {
     AttributeMetadata attrMeta = repoMeta.entityMetadata().idAttribute();
     String id = attrMeta.get(obj).toString();
     key = "@" + buildUri(config.getBaseUri(), repoMeta.name(), id);
   } else {
     key = conversionService.convert(obj, String.class);
   }

The conversionService is never executed


Reference URL: https://api.github.com/repos/SpringSource/spring-data-rest/issues/66

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.