spring-projects / spring-data-couchbase

Provides support to increase developer productivity in Java when using Couchbase. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-couchbase
Apache License 2.0
274 stars 190 forks source link

Jackson2RepositoryPopulatorFactoryBean fails to understand id alias [DATACOUCH-258] #571

Open spring-projects-issues opened 7 years ago

spring-projects-issues commented 7 years ago

Abhijit Sarkar opened DATACOUCH-258 and commented

Jackson2RepositoryPopulatorFactoryBean coming from spring-data-commons:1.12.13.RELEASE fails with the following error message when the document id field is aliased.

public class AppIdAppKeyPair {
    @Id
    @Field("alias")
    private String appId;
    @Field
    private String appKey;
}
[
  {
    "_class": "package.AppIdAppKeyPair",
    "alias": "admin",
    "appKey": "secret"
  }
]
@Bean
Jackson2RepositoryPopulatorFactoryBean jackson2Populator() {
    ClassPathResource resource1 = new ClassPathResource("/auth.json");
    Jackson2RepositoryPopulatorFactoryBean jackson2Populator = new Jackson2RepositoryPopulatorFactoryBean();
    jackson2Populator.setResources(new Resource[]{resource1});

    return jackson2Populator;
}

org.springframework.data.mapping.model.MappingException: An ID property is needed, but not found on this entity.


Affects: 1.4.6 (Gosling SR6)

1 votes, 2 watchers

spring-projects-issues commented 6 years ago

Jack Lever commented

This issue persists in 3.0.5.RELEASE.

I can reproduce this issue using a couchbase repository using this code :

Optional<User> userPresent = userRepository.findById(UUID.fromString(userId));
        Optional<Organisation> orgNull = organisationRepository.findById(UUID.fromString(userId));
        Optional<User> userNull = userRepository.findById(UUID.fromString(orgId));
        Optional<Organisation> orgPresent = organisationRepository.findById(UUID.fromString(orgId));

In this case orgNull and userNull still return objects of the type of the repository initialised with the default constructor