You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've created a reproducer to demonstrate the issue. The repository is available here.
Summary
The main entity Movie has a OneToMany relation to Ratings. Ratings has a composite primary key with movieID and ratingPlatformId. Only the Movie entity has a REST repository, and IDs are exposed. A single movie API exists where GET works fine, but updating via PUT doesn't. Updating the ratings list gives unexpected results. For example:
Before:
{
"id": 2,
"name": "The Dark Knight",
"ratings": [
{
"ratingPlatformId": 1,
"score": 10
}
]
}
PUT Request:
{
"id": 2,
"name": "The Dark Knight",
"ratings": [
{
"ratingPlatformId": 2,
"score": 2
}
]
}
Expectation:
The rating for ratingPlatformId 1 should be deleted, and a new one with ratingPlatformId 2 should be created.
Actual Result:
{
"id": 2,
"name": "The Dark Knight",
"ratings": [
{
"ratingPlatformId": 1,
"score": 2
}
]
}
I debugged a bit and ratingPlatformId is not considered at all during the PUT operation and gets skipped here as it is an ID:
@mp911de, @odrotbohm - any chance you find the time to have a look on this issue? Thanks in advance. Just let me know if further information is required.
Reproducer:
I've created a reproducer to demonstrate the issue. The repository is available here.
Summary
The main entity
Movie
has aOneToMany
relation toRatings
.Ratings
has a composite primary key withmovieID
andratingPlatformId
. Only theMovie
entity has a REST repository, and IDs are exposed. A single movie API exists where GET works fine, but updating via PUT doesn't. Updating the ratings list gives unexpected results. For example:Before:
PUT Request:
Expectation:
The rating for ratingPlatformId 1 should be deleted, and a new one with ratingPlatformId 2 should be created.
Actual Result:
I debugged a bit and ratingPlatformId is not considered at all during the PUT operation and gets skipped here as it is an ID:
spring-data-rest/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java
Lines 688 to 690 in aaadc34
The only working setup is inspired by AresEkb from #2324 and involves:
HashMap
for theOneToMany
ratings and writinggetRatings
andsetRatings
methods manually.RepositoryEntityController.putItemResource
to set the movie in the ratings.Branches
HashMap
and AOP workarounds.HashSet
and AOP, but adding list elements in the middle fails.HashSet
and without any AOP or workarounds; many tests fail.The text was updated successfully, but these errors were encountered: