spring-projects / spring-projects/spring-data-rest
Silent failure to edit a OneToMany association with PUT/PATCH [DATAREST-822]
@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
PJ Weisberg opened DATAREST-822 and commented
I have two entities defined like this:
@Entity
public class Vehicle implements Identifiable<Long> {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "vehicle")
private Set<Worker> workers = new HashSet<>();
// etc.
}
@Entity
@NoArgsConstructor
public class Worker implements Identifiable<Long>{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinTable(
name = "WorkerVehicle",
joinColumns = @JoinColumn(name = "WorkerID"),
inverseJoinColumns = @JoinColumn(name = "VehicleID")
)
private Vehicle vehicle;
// etc.
}
I can add a relationship by setting the Vehicle of the worker, like this:
PUT /hal/workers/5/vehicle HTTP/1.1
Content-Type: text/uri-list
http://localhost:8080/hal/vehicles/3
Then when I GET http://localhost:8080/hal/vehicles/3/workers, the result contains Worker 5.
However, if I try to add a worker to a vehicle, like this:
PUT /hal/vehicles/3/workers HTTP/1.1
Content-Type: text/uri-list
http://localhost:8080/hal/workers/1
I get a response of "204 No Content", but a subsequent GET of /hal/vehicles/3/workers/ does not include Worker 1.
I understand it may be intentional for you to only be able to modify the relationship from one side, but if that's the case then the response should be in the 4xx range rather than 2xx
2 votes, 3 watchers
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.