Ignore field for update in spring-r2dbc
Asked Answered
B

2

6

I am using spring r2dbc and ReactiveCrudRepository, I have a field which I need to ignore for when update query is generated

@Data
@Table(PRODUCT_TABLE)
public class ProductEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) // Id generated by database
    private Integer id;

    private Integer companyId;

    @Column(insertable=false, updatable = false)
    private String companyName;

    @NotBlank
    private String name;

    private VerificationStatus verificationStatus;
}

How can I ignore companyName in update query. I am able ignore it in insert query using @column but its not working for update

Blunger answered 16/5, 2020 at 15:23 Comment(0)
G
1

If you don't want to keep the field for update and insert, then mark the field with @Transient.

For example,

@Transient
private String companyName;

https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/annotation/Transient.html

Glennglenna answered 16/5, 2020 at 15:33 Comment(1)
But I do want to it use for select statements, it would be ignored in case of TransientBlunger
L
1

Simplify use

@ReadOnlyProperty

For example,

@ReadOnlyProperty
private String companyName;

https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/annotation/ReadOnlyProperty.html

Levitate answered 3/1, 2022 at 14:24 Comment(1)
this one will not allow insert field data to persistPoet

© 2022 - 2024 — McMap. All rights reserved.