Hello,
Setup:
Couchbase Server v.7.0.3, Spring Boot 2.6.6 with spring-data-couchbase:4.3.4 dependency
This is my data structure:
{
"_class": "myApp.model.Customer",
"_id": "customer/1111111111",
"_key": "1111111111",
"_rev": "_d0PzZqu---",
"activeFrom": "2022-03-07T12:58:12.3796699",
"customerID": "1111111111",
"name": "Max Mustermann",
"addresses": [
{
"priority": 1,
"city": "Darmstadt",
"street" : "Oldenburgerstr. 1",
"addressInput": {
"zipCodes": [
"DE_26133"
]
}
},
{
"priority": 2,
"city": "Frankfurt",
"street" : "Hanauerlandstr. 10",
"addressInput": {
"zipCodes": [
"DE_64807"
]
}
}
]
}
I don’t know how to query in Spring Data with the @Query - annotation just to get the customer by a zipCode.
@Repository
public interface ShortHaulRouteCouchbaseRepository extends CouchbaseRepository<ShortHaulRoutingRuleSetCouch, String> {
@Query("#{#n1ql.selectEntity} WHERE addresses.addressInput.zipCodes=$zipCode AND activeFrom <= $currentDate AND (activeTo = NULL OR activeTo > $currentDate) ORDER BY activeFrom DESC")
Customer getActiveCustomer(@Param("currentDate") String currentDate, @Param("zipCode") String zipCode );
}
I tried with Spring Data’s helo soemthing like :
Customer = findByAddresses_AddressInput_ZipCodes(String zipCode);
Unfortunatly I recieve this:
java.lang.NullPointerException: null
at org.springframework.data.couchbase.core.ReactiveFindByQueryOperationSupport$ReactiveFindByQuerySupport.lambda$null$1(ReactiveFindByQueryOperationSupport.java:151) ~[spring-data-couchbase-4.1.5.jar:4.1.5]
I also tried with SpEl with the same result.
Kindly suggest where I am doing it incorrectly.
Kind Regards,
Argin