Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table with hash and range key in Kotlin #240

Closed
rheber opened this issue Mar 15, 2019 · 2 comments
Closed

Table with hash and range key in Kotlin #240

rheber opened this issue Mar 15, 2019 · 2 comments

Comments

@rheber
Copy link

rheber commented Mar 15, 2019

Expected Behavior

I'm working on a Kotlin program and a table I'm writing a crud repository for uses both a hash and range key. After consulting this page:

https://github.com/derjust/spring-data-dynamodb/wiki/Use-Hash-Range-keys

I've written what I believe to be the Kotlin equivalent of the necessary code. As such I would expect the code to compile with no errors.

Actual Behavior

Attempting to save an entry to the table produces this exception:

com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: One of the required keys was not given a value

Steps to Reproduce the Problem

Here are the relevant sections of the code:

interface FoobarRepository: CrudRepository<FoobarEntry, FoobarEntryId> {
    fun findAllByFoobarCode(foobarCode: String): Iterable<FoobarEntry>
}

data class FoobarEntryId (
    @get:DynamoDBHashKey var foobarCode: String? = null,
    @get:DynamoDBRangeKey var foobarKey: String? = null
)

@DynamoDBTable(tableName = "Foobars")
class FoobarEntry(
    @Id
    private var foobarEntryId: FoobarEntryId? = null,

    @get:DynamoDBHashKey
    @get:DynamoDBAttribute
    var foobarCode: String? = null,

    @get:DynamoDBRangeKey
    @get:DynamoDBAttribute
    var foobarKey: String? = null,

    @get:DynamoDBAttribute
    var foobarValue: String? = null
)

@Component
class LocalDatabase(
    val foobarRepository: FoobarRepository
) {

    @PostConstruct
    fun start () {
        setupTestData()
    }

    private fun setupTestData() {
            foobarRepository.save(FoobarEntry(
            foobarEntryId = FoobarEntryId(foobarCode = "1", foobarKey = "key"),
            foobarCode = "1",
            foobarKey = "key",
            foobarValue = "value"
        ))
    }
}

The exception occurs when trying to instantiate a LocalDatabase bean.

Specifications

  • Spring Data DynamoDB Version: 5.1.0
  • Spring Data Version: 2.1.2
  • AWS SDK Version: 1.11.228
  • Java Version: 1.8
  • Platform Details: Mac
@alex-arana
Copy link

alex-arana commented Mar 20, 2019

I've created an article in the project wiki to demonstrate the modelling of Hash/Range partition keys using Spring-Data-style composite primary keys in Kotlin:

Composite Primary Keys Kotlin Example

Feel free to close the ticket if this solves your issue.

@rheber
Copy link
Author

rheber commented Mar 21, 2019

Thanks @alex-arana. It turned out I just had a typo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants