I have a Student object which I am storing in a jsonb column.
The Student has Address and an Array of Subjects. The jsonb column data looks something like this:
{
"id": 1,
"name": "John doe",
"address": {
"street": "123 street",
"city": "new york",
"country": "US",
"postalcode": "123456"
},
"subjects": [
{
"subjectId": "123",
"name": "science",
"modules": 12
},
{
"subjectId": "124",
"name": "physics",
"modules": 5
}
]
}
So, using the spring boot data JPA, I want to achieve:
- Modify the address.
- Modify the items in the Subjects list.
- Add/Delete subjects from the list.
I have seen the options like:
- Fetching the whole object and replace it with the updated one.
- Use of ‘jsonb_set’ function.
But, is there any other way we can get the full control and more flexibility for modifying the jsonb data using the spring data JPA?
Overall I am looking for the best way to handle this scenario.