zy_sun
zy_sun

Reputation: 443

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);
    }
}

Upvotes: 1

Views: 1335

Answers (2)

ryouga888
ryouga888

Reputation: 1

use org.springframework.data.annotation.Transient instead of javax.persistence.Transient

Upvotes: 0

Elyorbek Ibrokhimov
Elyorbek Ibrokhimov

Reputation: 1106

@ReadOnlyProperty annotation works.

Upvotes: 2

Related Questions