spring-data-relational
spring-data-relational copied to clipboard
Do not delete mapped entities of an aggregate marked with @ReadOnlyProperty
So I have been using spring-data-jdbc for one of my applications
Basically I have a 1-1 relationship of a class let's call it this way
class Person{
Long id;
String name;
@MappedCollection(idColumn = "person_id")
@ReadOnlyProperty
BirthDate birthdate;
}
What happened when I called repository.save(person) is that always the birthday is removed and inserted back. Is this an intended design decision? This feature would make it repositories way more powerful. I had a use case similar to flyweight pattern where I have big payloads that never change. Is it possible for me to explore ways of adding such functionality? I will be very happy to contribute.
So, are you suggesting to not "remove and insert back", OR what? What specific query do you have, @hussainkarafallah ? Please clarify.
@rishiraj88 Yes exactly. I think @ReadOnlyProperty annotation would kill performance in any Row-based database as even if it's excluded from the UPDATE statement the row will be rewritten. The same for mappings to other tables. If we remove them and insert again then we lost a lot of performance.
Of course I am not discussing here the logic of delete and insert as it makes sense from Aggregate perspective. But if the property / entity is @ReadOnlyProperty, I think a lot of power can be added to the framework. I hope it makes sense.
Looking at the existing code, this is already the way it should behave.
Therefore, please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.