spring-data-couchbase
spring-data-couchbase copied to clipboard
Jackson2RepositoryPopulatorFactoryBean fails to understand id alias [DATACOUCH-258]
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
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