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

Add an "InsertOnly" annotation to support a write-once semantic. [DATAJDBC-416]

Open spring-projects-issues opened this issue 6 years ago • 4 comments

Tyler K Van Gorder opened DATAJDBC-416 and commented

It would be nice to mark attributes on an entity as "InsertOnly", such that they are included during and insert but excluded from an update. A use-case for such an annotation can be applied to the "created" auditing columns. 

You want to ensure the auditing columns are set when the entity is inserted and you want to prevent those same fields from being overwritten during the update. 


1 votes, 2 watchers

spring-projects-issues avatar Sep 16 '19 17:09 spring-projects-issues

The annotation should be '@InsertOnlyProperty' modelled after '@ReadOnlyProperty'.

schauder avatar Jan 13 '22 09:01 schauder

Any implementation would currently only work for Aggregate Root properties. Therefore this has to wait until we have a better way of updating inner entities in place.

schauder avatar Jan 31 '22 08:01 schauder

@schauder How about adding an annotation such as @Condition when calling save?

class Student {
  ...
  @Condition
  String name;
}
UPDATE student
SET ...
WHERE id = :id AND name = :name

taeyeon-Kim avatar Apr 20 '22 10:04 taeyeon-Kim

@schauder Please consider it

taeyeon-Kim avatar Jun 24 '22 11:06 taeyeon-Kim

@taeyeon-Kim I'm confused by what the relation to the original issue is. Could you please clarify, or create a separate issue where you explain what the use case for such a construct is?

schauder avatar Sep 08 '22 13:09 schauder

May be its too late write any suggestion. But let me write my idea about it. What if will be added property ChangeConditionProperty which get array of strings such as "INSERT", "UPDATE". And then from this condition attribute may be included or excluded from an update script. Thanks!

Husan avatar Nov 14 '22 06:11 Husan