We are using below versions of java sdk
com.couchbase.client:core-io:2.4.1
com.couchbase.client:java-client:3.3.4
We have two classes
// BaseClass
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@EqualsAndHashCode
@ToString
@Document
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "request"
)
@JsonSubTypes({
@JsonSubTypes.Type(value = InitialPrice.class, name = "InitialPrice")
})
public class PriceChange {
@Id
private String id;
private String priceChangeIntentId;
private String locationClusterId;
private Instant effectiveDateTime;
private String itemNumber;
@JsonIgnore
public String getParentCluster() {
return this.impactedCluster !=null ? this.impactedCluster : this.locationClusterId;
}
}
//Extended class
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper=true)
@ToString(callSuper = true)
@Document
public class InitialPrice extends PriceChange {
private String initialPriceIntentId;
}
@Repository
public interface PriceChangeCouchbaseRepository extends ReactiveCouchbaseRepository<PriceChange, String> {
@Query("#{#n1ql.selectEntity} "
+ "WHERE (#{#n1ql.filter} "
+ "AND itemNumber = $1 "
+ "AND effectiveDateTime <= $2 "
+ "AND locationClusterId = $3) "
+ "OR (_class = 'com.price.domain.entity.InitialPrice' "
+ "AND itemNumber = $1 "
+ "AND effectiveDateTime <= $2 "
+ "AND locationClusterId = $3) "
+ "order by effectiveDateTime DESC ")
Flux<PriceChange> fetchCurrentPrice(String itemNumber, Long effectiveDateTime, String locationClusterId);
}
The above is resulting in the below if only IntitialPrice exists:
SELECT `_class`,
META(`prices`).`id` AS __id,
`priceChangeIntentId`,
`locationClusterId`,
`effectiveDateTime`,
`itemNumber`
FROM `prices`
WHERE (`_class` = 'com.price.domain.entity.PriceChange'
AND itemNumber = $1
AND effectiveDateTime <= $2
AND locationClusterId = $3)
OR (_class = 'com.price.domain.entity.InitialPrice'
AND itemNumber = $1
AND effectiveDateTime <= $2
AND locationClusterId = $3)
ORDER BY effectiveDateTime DESC
With older versions where ReactiveCouchbaseSortingRepository is supported this is resulting in the below:
SELECT `_class`,
META(`prices`).`id` AS __id,
`priceChangeIntentId`,
`locationClusterId`,
`effectiveDateTime`,
`itemNumber`,
`initialPriceIntentId`
FROM `prices`
WHERE (`_class` = 'com.price.domain.entity.PriceChange'
AND itemNumber = $1
AND effectiveDateTime <= $2
AND locationClusterId = $3)
OR (_class = 'com.price.domain.entity.InitialPrice'
AND itemNumber = $1
AND effectiveDateTime <= $2
AND locationClusterId = $3)
ORDER BY effectiveDateTime DESC
The initialPriceIntentId field of inherited class is missing with ReactiveCouchbaseRepository in SELECT clause.
What can we do to make this work like earlier where the fields from inherited class are as also selected?
I tried using the below SPEL to achieve this,
#{#n1ql.selectEntity},#{#n1ql.selectFields('initialPriceIntentId')}
but facing below issue:
org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method selectFields(java.lang.String) cannot be found on type org.springframework.data.couchbase.repository.query.StringBasedN1qlQueryParser$N1qlSpelValues