【发布时间】:2020-11-11 23:07:13
【问题描述】:
预期行为
Repository 对只使用 hashKey 和 rangeKey 属性的方法执行查询,结果如下:
"{"TableName":"music","KeyConditionExpression":"artist = :_artist and begins_with(title, :_title)","ExpressionAttributeValues":{":_artist":{"S":"Djavan"},":_title":{"S":"Eu te devoro"}}}"
实际行为
Repository 对仅使用 hashKey 和 rangeKey 属性的方法执行 scanFilter,结果如下:
"{"TableName":"music","ScanFilter":{"artist":{"AttributeValueList":[{"S":"Djavan"}],"ComparisonOperator":"EQ"},"title":{"AttributeValueList":[{"S":"Eu te devoro"}],"ComparisonOperator":"BEGINS_WITH"}}}"
重现问题的步骤
使用名为 Music 的实体
@DynamoDBTable(tableName = "music")
data class Music(
@field:Id
@DynamoDBIgnore
val id: MusicId = MusicId(),
var genre: String? = null
) {
@DynamoDBHashKey(attributeName = "artist")
fun getArtist() = id.artist
fun setArtist(artist: String) {
id.artist = artist
}
@DynamoDBHashKey(attributeName = "title")
fun getTitle() = id.title
fun setTitle(title: String) {
id.title = title
}
}
@DynamoDBDocument
data class MusicId(
@field:DynamoDBHashKey(attributeName = "artist")
var artist: String? = null,
@field:DynamoDBRangeKey(attributeName = "title")
var title: String? = null
) : Serializable
还有一个仓库
@EnableScan //I know that if I remove this annotation, enables won't be permitted, but the problem is that the implementation code doesn't recognize my method as a key query and if I remove this annotation, the method falls on invocation
interface MusicRepository : CrudRepository<Music, MusicId> {
fun findByArtistAndTitleStartingWith(artista: String, sortKey: String): List<Music>
}
当我调用时:
@PostConstruct
fun init() {
println(musicRepository.findByArtistAndTitleStartingWith("Djavan", "Eu te devoro").joinToString())
}
如上所示,日志显示我对 AWS 的调用
规格
- 库:https://github.com/boostchicken/spring-data-dynamodb
- Spring Data DynamoDB 版本:5.2.5
- Spring 数据版本:未使用
- Spring Boot Starter Web 版本:2.3.4.RELEASE
- AWS 开发工具包版本:1.11.573
- Java 版本:11
- 平台详情:Windows
我有什么问题吗?还是spring数据创建对aws的正确查询的另一种方法?
【问题讨论】:
标签: java spring-data amazon-dynamodb