spring-projects / spring-projects/spring-data-rest
_embedded relation attribute results are different each execution. [DATAREST-839]
@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
MyeongHyeonLee opened DATAREST-839 and commented
This bug is caused by complexity reasons.
I wrote test case what is problem.
This test case is so wired.
There are one parent(Animal) and two child(Dog, Cat) classes.
I want to expose 'animals' under '_embedded' json value ; not dogs, cats
like this :
"_embedded" : {
"animals" : [ {
"name" : "dog",
"message" : "hi",
"_links" : {
"self" : {
"href" : "/animals/com.example.sample.Animal$Id@2d07aacc"
}
}
}, {
"name" : "cat",
"message" : "hi2",
"_links" : {
"self" : {
"href" : "/animals/com.example.sample.Animal$Id@ff5d4f1"
}
}
} ]
}
}
I used @Relation on entities, implements @RestController manually and id is @EmbeddedId.
First call result is ok but, after calls are different.
second call :
"_embedded" : {
"cats" : [ {
"name" : "cat",
"message" : "hi2",
"_links" : {
"self" : {
"href" : "/animals/com.example.sample.Animal$Id@553fbe94"
}
}
} ],
"dogs" : [ {
"name" : "dog",
"message" : "hi",
"_links" : {
"self" : {
"href" : "/animals/com.example.sample.Animal$Id@7cdc4070"
}
}
} ]
}
}
- Reason
- I implements
@RestControllermanually that sub types aren't registered cache.
(PersistentEntitiesResourceMappings.hasMappingFor() is false) - So RelProvider choose AnnotationRelProvider; second priority.
- Finally PersistentEntityJackson2Module call PersistentEntitiesResourceMappings.getMetadataFor() then put to cache these sub types.
(Because of@EmbeddedIdis Association) - Second call's result are different. RepositoryRelProvidre find these types in cache that RepositoryRelProvider choosed
Affects: 2.4.4 (Gosling SR4)
Reference URL: https://github.com/myeonhyeonLee/spring-data-rest-resourcemapping-bug
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.