I have the model Person with relations to Account and School models:
@Entity
public class Person {
@GeneratedValue
@Id
private Long id;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@RestResource(exported = false)
private Account account;
@ManyToOne(fetch = FetchType.EAGER)
private School school;
}
The idea - is that account should be editable only with user model. For the school in my requests I'm sending the url something like that:
"school": "http://localhost:8080/schools/2"
It's working ok for POST requests. I'm sending json like that:
{
"account": {
"username": "test",
"email": "testEmail"
},
"school": "http://localhost:8080/schools/2"
}
After that request new person and account are created, for school_id - I have needed value in database.
It's working ok for PATCH requests. I'm sending json like that:
{
"account": {
"username": "new test",
"email": "new testEmail"
},
"school": "http://localhost:8080/schools/1"
}
After that request needed fields are updated in database.
The issue in PUT request. I'm sending json like that:
{
"account": {
"username": "put test",
"email": "put testEmail"
},
"school": "http://localhost:8080/schools/2"
}
The result of this request:
in accounts table I have new row, old account row is not updated and not deleted;
school is not updated.
I want to have the same behavior for PUT operations as I have for PATCH request. I need to update needed fields by PUT request. I need a help. What should I change?