spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

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

Open hussainkarafallah opened this issue 1 year ago • 3 comments

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.

hussainkarafallah avatar Jan 09 '24 02:01 hussainkarafallah

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

rishiraj88 avatar Jan 09 '24 02:01 rishiraj88

@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 avatar Jan 09 '24 04:01 hussainkarafallah

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.

hussainkarafallah avatar Jan 09 '24 04:01 hussainkarafallah

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.

schauder avatar Jun 11 '24 07:06 schauder

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 avatar Jun 18 '24 08:06 spring-projects-issues

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.

spring-projects-issues avatar Jun 25 '24 08:06 spring-projects-issues