0
votes

When I invoke a repository method that makes a key search in dynamo:

enter image description here

"{"TableName":"music","Key":{"artist":{"S":"Henrique"},"title":{"S":"Quinta_de_sol1"}},"ConsistentRead":false}"

this is aws output:

"{}"

And when i invoke another methos that makes a find using sortKey start with:

enter image description here

this is sent to aws:

"{"TableName":"music","ConsistentRead":true,"KeyConditions":{"artist":{"AttributeValueList":[{"S":"Djavan"}],"ComparisonOperator":"EQ"},"title":{"AttributeValueList":[{"S":"Tempo"}],"ComparisonOperator":"BEGINS_WITH"}},"ScanIndexForward":true}"

and this is the return:

"{"Count":0,"Items":[],"ScannedCount":0}"

Steps to Reproduce the Problem

Using a entity named Music

@DynamoDBTable(tableName = "music")
data class Music(

        @get:DynamoDBHashKey(attributeName = "artist")
        var artist: String? = null,

        @get:DynamoDBRangeKey(attributeName = "title")
        var title: String? = null,

        var genre: String? = null
) {

    @Id
    private var id: MusicId? = null
        get() = MusicId(artist, title)
}

@DynamoDBDocument
data class MusicId(

        @field:DynamoDBHashKey(attributeName = "artist")
        var artist: String? = null,

        @field:DynamoDBRangeKey(attributeName = "title")
        var title: String? = null
) : Serializable

And a repository

interface MusicRepository : CrudRepository<Music, MusicId> {

    fun findByArtistAndTitle(artist: String, title: String): List<Music>

    fun findByArtistAndTitleStartingWith(artista: String, sortKey: String): List<Music>
}

And when i invoke:

@PostConstruct
    fun init() {
        println(musicRepository.findByArtistAndTitleStartingWith("Djavan", "Eu te devoro").joinToString())
    }

Specifications

Someone know if is there a clean way to guarantee that the dynamo repo will never return a list that only accepts non null elements, with null elements?

1

1 Answers

2
votes

To write a Spring application that invokes Amazon DynamoDB, consider using the official Amazon DynamoDB Java V2 API and the enhanced client within a Spring project.

Map items in DynamoDB tables

If you are not familiar with the AWS SDK for Java V2, please refer to this Quick Start.