does not map a @DynamoDBHashKey attribute; ensure a public, zero-parameter get method/field is annotated

Problem:

“`
Class does not map a @DynamoDBHashKey attribute; ensure a public, zero-parameter get method/field is annotated
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: Class does not map a @DynamoDBHashKey attribute; ensure a public, zero-parameter get method/field is annotated
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingsRegistry$Mappings.getHashKey(DynamoDBMappingsRegistry.java:245)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.needAutoGenerateAssignableKey(DynamoDBMapper.java:682)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:708)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:669)
“`

Solution:

Need to add `@beanGetter` to: `@(DynamoDBHashKey @beanGetter)`

e.g.: `@(DynamoDBHashKey @beanGetter)(attributeName=”ID”) @BeanProperty var ID: String = null`

Problem:

“`
The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: )
com.amazonaws.AmazonServiceException: The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: )
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1389)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:902)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:607)
at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:376)
at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:338)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:287)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:2000)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:1970)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.updateItem(AmazonDynamoDBClient.java:1798)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$SaveObjectHandler.doUpdateItem(DynamoDBMapper.java:1095)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$2.executeLowLevelRequest(DynamoDBMapper.java:795)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$SaveObjectHandler.execute(DynamoDBMapper.java:974)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:824)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:669)
“`

Solution:

`attributeName` need to be provided for `DynamoDBHashKey` explicitly (even if it matches the field name).

e.g.: @(DynamoDBHashKey @beanGetter)(attributeName="ID") @BeanProperty var ID: String = null

 

 

com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: Class org.activeintel.al.crawler.LocationRecord does not map a @DynamoDBHashKey attribute; ensure a public, zero-parameter get method/field is annotated
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingsRegistry$Mappings.getHashKey(DynamoDBMappingsRegistry.java:245)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.needAutoGenerateAssignableKey(DynamoDBMapper.java:682)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:708)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:669)

About Neil Rubens

see http://ActiveIntelligence.org
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*