@Query在Spring Boot(JPA)+ Azure Cosmos db中不起作用 [英] @Query doesn't work in Spring Boot (JPA ) + Azure Cosmos db

查看:74
本文介绍了@Query在Spring Boot(JPA)+ Azure Cosmos db中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一些物联网应用程序.数据位于Azure Cosmos DB中.例子)

I'm developing some IoT application. Data is in Azure Cosmos DB. example)

{
        "id": "3ebd07c0-0740-466f-acb4-1e04a58cdf1a",
        "serviceId": 1,
        "deviceId": 1,
        "contents": "{\"temperature\":34.797642257199705,\"humidity\":79.18982439419167,\"illuminance\":100}",
        "date": 1552376519931
    }

所以.我想使用这样的自定义查询

So. I want to use custom query like this

public interface DeviceTelemetryRepository extends DocumentDbRepository<DeviceTelemetry, String> {

    @Query("SELECT a.deviceId FROM device_telemetry a where a.deviceId=:deviceId and a.date >=:from and a.date <=:to")
    List<DeviceTelemetry> findTelemetryByDeviceId(@Param("deviceId") int deviceId,
                                     @Param("from") long from,
                                     @Param("to") long to    );
}


@Data
@NoArgsConstructor
@AllArgsConstructor

public class DeviceTelemetry {
    private String id;
    private int serviceId;
    private int deviceId;
    private String contents;
    private long date;
}

但是它不起作用.我已经在Azure门户上测试了它的查询和数据.没关系.

But it doesn't work. I already tested it's query and data on Azure portal. It was ok.

我认为"DeviceTelemetryRepository扩展了DocumentDbRepository"无法识别@Query.

I think that "DeviceTelemetryRepository extends DocumentDbRepository" cannot recognize @Query.

您对Spring Boot JPA + Azure Cosmos DB有什么建议吗?谢谢!

Do you have any suggestion about Spring Boot JPA + Azure Cosmos DB ? Thank you!

推荐答案

Microsoft的spring-data-cosmosdb库不支持@Query注释.

Microsoft's spring-data-cosmosdb library doesn't support the @Query annotation.

这篇关于@Query在Spring Boot(JPA)+ Azure Cosmos db中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆