I think I have tried all kind of combinations of annotation but I am getting either Sorting not supported for scan expressions or no HASH key for GSI or Both the Hash Key and the Range Key element in the KeySchema have the same name error.
Expectation:
Get values with pagination and sort by createdAt field descending.
Repository:
@Repository
@EnableScan
@EnableScanCount
interface StatementRepository : DynamoDBPagingAndSortingRepository<Statement?, String?> {
override fun findById(id: String): Optional<Statement?>
}
Entity:
@DynamoDBTable(tableName = "statements")
class Statement {
@get:DynamoDBAutoGeneratedKey
@get:DynamoDBHashKey
var id: String? = null
@get:DynamoDBAttribute
var statementText: String? = null
@get:DynamoDBAttribute
var source: String? = null
@get:DynamoDBAttribute
@get: DynamoDBIndexHashKey(globalSecondaryIndexName = "id")
@get: DynamoDBIndexRangeKey(globalSecondaryIndexNames = ["id-createdAt-index"])
var createdAt: Long? = null
}
Service:
statementRepository.findAll(PageRequest.of(page, size, Sort.by("createdAt").descending())).forEach {...
I tried almost every solution on the internet and all combination of DynamoDBIndexHashKey and DynamoDBIndexRangeKey annotations but getting diffrent errors.
Note:
Paging was working, the problem started when applied sorting as Sort.by("createdAt").descending()
Index on the table (created myself during hit-and-trail):
Please check the annotations and help me to place them right or let me know if I am missing anything.
I am also new to Kotlin but I have knowledge of Java.
