spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
753 stars 345 forks source link

Do not delete mapped entities of an aggregate marked with @ReadOnlyProperty #1715

Closed hussainkarafallah closed 2 months ago

hussainkarafallah commented 8 months ago

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.

rishiraj88 commented 8 months ago

So, are you suggesting to not "remove and insert back", OR what? What specific query do you have, @hussainkarafallah ? Please clarify.

hussainkarafallah commented 8 months ago

@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.

hussainkarafallah commented 8 months ago

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.

schauder commented 2 months ago

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.

spring-projects-issues commented 2 months ago

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.

spring-projects-issues commented 2 months ago

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.