Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Sep 16, 2019 · 6 comments
Assignees
Labels
in: statement-builder SQL Statement builder API status: blocked An issue that's blocked on an external project change type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

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

@schauder
Copy link
Contributor

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

@schauder schauder added the status: blocked An issue that's blocked on an external project change label Jan 31, 2022
@schauder
Copy link
Contributor

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.

@taeyeon-Kim
Copy link
Contributor

@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
Copy link
Contributor

@schauder Please consider it

@schauder
Copy link
Contributor

schauder commented Sep 8, 2022

@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 added a commit that referenced this issue Sep 13, 2022
For Spring Data JDBC you may now annotate properties of the aggregate root with `@InsertOnlyProperty`.
Properties annotated in such way will be written to the database only during insert operations, but they will not be updated afterwards.

Closes #637
schauder added a commit that referenced this issue Sep 20, 2022
For Spring Data JDBC you may now annotate properties of the aggregate root with `@InsertOnlyProperty`.
Properties annotated in such way will be written to the database only during insert operations, but they will not be updated afterwards.

Closes #637
schauder added a commit that referenced this issue Sep 20, 2022
You may now annotate properties of the aggregate root with `@InsertOnlyProperty`.
Properties annotated in such way will be written to the database only during insert operations, but they will not be updated afterwards.

Closes #637
@schauder schauder added this to the 3.0 RC1 (2022.0.0) milestone Oct 7, 2022
@Husan
Copy link

Husan commented Nov 14, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: statement-builder SQL Statement builder API status: blocked An issue that's blocked on an external project change type: enhancement A general enhancement
Projects
None yet
4 participants