I am trying to filter the employee data by addressType from cosmosdb by using join in my spring boot application.
Below is the employee data in cosmosdb
{
"id": "125",
"name": "Dolly",
"addresses": [
{
"addressType": "home",
"street": "Nagpur"
},
{
"addressType": "office",
"street": "Pune"
}
] }
This is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.employee.service</groupId>
<artifactId>employee-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>employee-service</name>
<description>employee service</description>
<properties>
<java.version>17</java.version>
<spring-cloud-azure.version>5.11.0</spring-cloud-azure.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-starter-data-cosmos</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-dependencies</artifactId>
<version>${spring-cloud-azure.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
below is my Repository class
@Repository
public interface EmployeeRepository extends CosmosRepository<Employee, String> {
@Query("SELECT * FROM c JOIN a IN c.addresses WHERE a.addressType = @addressType")
List<Employee> findByAddressType(@Param("addressType") String addressType);
}
Below is my service class
@Service
public class EmployeeService {
@Autowired
private EmployeeRepository employeeRepository;
public List<Employee> findByAddressType(String addressType) {
return employeeRepository.findByAddressType(addressType);
}
}
Below is my employeeController
@RestController
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/employees/by-address-type")
public List<Employee> getEmployeesByAddressType(@RequestParam String addressType) {
return employeeService.findByAddressType(addressType);
}
}
When I am trying to call this api I am getting below error
com.azure.cosmos.CosmosException: {“innerErrorMessage”:”{“code”:”BadRequest”,”message”:”One of the input values is invalid.rnActivityId: d3c95663-5138-4c73-a700-c06100fbb54b, Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0″}, StatusCode: BadRequest”,”cosmosDiagnostics”:{“userAgent”:”azsdk-java-cosmos/4.57.0 Windows11/10.0 JRE/17.0.10 az-sd-cos/5.11.0″,”activityId”:”d3c95663-5138-4c73-a700-c06100fbb54b”,”requestLatencyInMs”:926,”requestStartTimeUTC”:”2024-06-13T19:04:51.480443200Z”,”requestEndTimeUTC”:”2024-06-13T19:04:52.407243700Z”,”responseStatisticsList”:[],”supplementalResponseStatisticsList”:[],”addressResolutionStatistics”:{},”regionsContacted”:[“north europe”],”retryContext”:{“statusAndSubStatusCodes”:null,”retryLatency”:0,”retryCount”:0},”metadataDiagnosticsContext”:{“metadataDiagnosticList”:null},”serializationDiagnosticsContext”:{“serializationDiagnosticsList”:null},”gatewayStatisticsList”:[{“sessionToken”:null,”operationType”:”QueryPlan”,”resourceType”:”Document”,”statusCode”:400,”subStatusCode”:0,”requestCharge”:0.0,”requestTimeline”:[{“eventName”:”connectionCreated”,”startTimeUTC”:”2024-06-13T19:04:51.495093Z”,”durationInMilliSecs”:644.9572},{“eventName”:”connectionConfigured”,”startTimeUTC”:”2024-06-13T19:04:52.140050200Z”,”durationInMilliSecs”:0.0},{“eventName”:”requestSent”,”startTimeUTC”:”2024-06-13T19:04:52.140050200Z”,”durationInMilliSecs”:1.9623},{“eventName”:”transitTime”,”startTimeUTC”:”2024-06-13T19:04:52.142012500Z”,”durationInMilliSecs”:257.2143},{“eventName”:”received”,”startTimeUTC”:”2024-06-13T19:04:52.399226800Z”,”durationInMilliSecs”:1.0335}],”partitionKeyRangeId”:null,”responsePayloadSizeInBytes”:0,”exceptionMessage”:”{“code”:”BadRequest”,”message”:”One of the input values is invalid.rnActivityId: d3c95663-5138-4c73-a700-c06100fbb54b, Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0″}, StatusCode: BadRequest”,”exceptionResponseHeaders”:”{Server=Compute, x-ms-gatewayversion=2.0.0, Content-Length=215, Date=Thu, 13 Jun 2024 19:04:51 GMT, x-ms-activity-id=d3c95663-5138-4c73-a700-c06100fbb54b, Content-Type=application/json, x-ms-substatus=0}”}],”samplingRateSnapshot”:1.0,”systemInformation”:{“usedMemory”:”43060 KB”,”availableMemory”:”4048844 KB”,”systemCpuLoad”:”(2024-06-13T19:04:27.028627500Z 9.4%), (2024-06-13T19:04:32.042307300Z 3.9%), (2024-06-13T19:04:37.042019800Z 10.7%), (2024-06-13T19:04:42.031689200Z 4.3%), (2024-06-13T19:04:47.037958800Z 5.2%), (2024-06-13T19:04:52.032517900Z 4.2%)”,”availableProcessors”:8},”clientCfgs”:{“id”:1,”machineId”:”uuid:1c6ce759-d9d9-464e-ab2e-6992ad04cfec”,”connectionMode”:”DIRECT”,”numberOfClients”:1,”excrgns”:”[]”,”clientEndpoints”:{“https://dev-db-account.documents.azure.com:443/”:1},”connCfg”:{“rntbd”:”(cto:PT5S, nrto:PT5S, icto:PT0S, ieto:PT1H, mcpe:130, mrpc:30, cer:true)”,”gw”:”(cps:1000, nrto:PT1M, icto:PT1M, p:false)”,”other”:”(ed: true, cs: false, rv: true)”},”consistencyCfg”:”(consistency: null, mm: true, prgns: [])”,”proactiveInitCfg”:””,”e2ePolicyCfg”:””,”sessionRetryCfg”:””}}}
at com.azure.cosmos.BridgeInternal.createCosmosException(BridgeInternal.java:478) ~[azure-cosmos-4.57.0.jar:4.57.0]
at com.azure.cosmos.implementation.RxGatewayStoreModel.validateOrThrow(RxGatewayStoreModel.java:504) ~[azure-cosmos-4.57.0.jar:4.57.0]
at com.azure.cosmos.implementation.RxGatewayStoreModel.lambda$toDocumentServiceResponse$1(RxGatewayStoreModel.java:365) ~[azure-cosmos-4.57.0.jar:4.57.0]
at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:106) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:74) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:200) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:122) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.core.publisher.FluxDoFinally$DoFinallySubscriber.onNext(FluxDoFinally.java:113) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.core.publisher.FluxHandleFuseable$HandleFuseableSubscriber.onNext(FluxHandleFuseable.java:194) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.core.publisher.Operators$BaseFluxToMonoOperator.completePossiblyEmpty(Operators.java:2097) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.core.publisher.MonoCollectList$MonoCollectListSubscriber.onComplete(MonoCollectList.java:118) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:260) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:144) ~[reactor-core-3.6.6.jar:3.6.6]
at reactor.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:415) ~[reactor-netty-core-1.1.19.jar:1.1.19]
at reactor.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:446) ~[reactor-netty-core-1.1.19.jar:1.1.19]
at reactor.netty.channel.ChannelOperations.terminate(ChannelOperations.java:500) ~[reactor-netty-core-1.1.19.jar:1.1.19]
at reactor.netty.http.client.HttpClientOperations.onInboundNext(HttpClientOperations.java:793) ~[reactor-netty-http-1.1.19.jar:1.1.19]
at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:114) ~[reactor-netty-core-1.1.19.jar:1.1.19]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289) ~[netty-handler-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[netty-codec-4.1.110.Final.jar:4.1.110.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) ~[netty-codec-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1475) ~[netty-handler-4.1.110.Final.jar:4.1.110.Final]
at io.netty.handler.ssl.SslHandler.decodeNonJdkCompatible(SslHandler.java:1349) ~[netty-handler-4.1.110.Final.jar:4.1.110.Final]
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1389) ~[netty-handler-4.1.110.Final.jar:4.1.110.Final]
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530) ~[netty-codec-4.1.110.Final.jar:4.1.110.Final]
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469) ~[netty-codec-4.1.110.Final.jar:4.1.110.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[netty-codec-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1407) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:918) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994) ~[netty-common-4.1.110.Final.jar:4.1.110.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.110.Final.jar:4.1.110.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.110.Final.jar:4.1.110.Final]
at java.base/java.lang.Thread.run(Thread.java:842) ~[na:na]
I tried SELECT * FROM c JOIN a IN c.addresses WHERE a.addressType = @addressType in cosmosdb data explore and it is working as expected but if i am using same query in spring boot it is not working.
I also tried by without @Query as well
@Repository
public interface EmployeeRepository extends CosmosRepository<Employee, String> {
List<Employee> findByAddressesAddressType(String addressType);
}
I am getting 200 response but result is blank array []
Request you to please help me resolve the issue is there any thing I am using wrong in my code.
Dolly Kumbhalkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.