spring-bootspring-data-jpaspring-dataspring-webfluxspring-data-r2dbc

Ignore field for query in spring-r2dbc


I am using spring r2dbc and ReactiveCrudRepository in spring webflex applicaition.

I have a field which I need to ignore for when select query is generated ( in Controller code is r2dbcEntityTemplate.select(Tenant.class) ).

I try to using @Transient ,But It doesn't work, still error: "Required property daysRemaining not found for class Tenant"

With my limited experience with r2dbc, Thanks in advance.

@Accessors(chain = true)
@Table(value = "tenant")
@Data
@Builder
public class Tenant {

    @Id
    private Long id;

    @Column(value = "organization_name")
    private String organizationName;

    @Version
    @Column
    private Long version;

  @Column
    private Boolean trialTenant;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
   @Column
    private LocalDateTime tenantExpiredTime;

    @Transient
 //Dynamically calculate the remaining time
    private Long daysRemaining;

  
    public Long getDaysRemaining() {

        return Optional.ofNullable(tenantExpiredTime)
                .map(localDateTime -> Duration.between(localDateTime, LocalDateTime.now()))
                .map(Duration::toDays)
                .orElseGet(() -> null);
    }
}

Solution

  • @ReadOnlyProperty annotation works.