DynamoDBMappingException:没有 HASH 键的映射

DynamoDBMappingException: no mapping for HASH key(DynamoDBMappingException:没有 HASH 键的映射)
本文介绍了DynamoDBMappingException:没有 HASH 键的映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写 DynamoDB Java 应用程序时,如果未正确配置表及其数据模型,则在从表中写入或检索时,您可能会收到无 HASH 键映射"错误.完整的例外类似于:

When writing a DynamoDB Java App you can receive the 'no mapping for HASH key' error when writing or retrieving from a table if the table and its data model are not configured correctly. The full exception would be similar to:

com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: <YourClassNameHere>;HASH键没有映射

推荐答案

这里有两个有用的东西:

Two helpful things to check here:

1) 对于散列键值的主要设置器,请确保正确设置了 @DynamoDBHashKey 表示法.@DynamoDBAttribute 不是用于表的主哈希键的正确键,@DynamoDBIndexHashKey 也不是.

1) For your main setter for your hash key value make sure that the @DynamoDBHashKey notation is correctly set. @DynamoDBAttribute is NOT the correct one to use for your table's main hash key and neither is @DynamoDBIndexHashKey.

2) 确保在表定义中定义了哈希键:

2) Make sure that the hash key is defined in the table definition:

        CreateTableRequest createTableRequest = new CreateTableRequest()
                .withTableName("testtable")
                .withKeySchema(
                        new KeySchemaElement("id", KeyType.HASH)
                )
                .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L))
                .withAttributeDefinitions(
                        new AttributeDefinition("id", "S")
                );

        CreateTableResult result = amazonDynamoDB.createTable(createTableRequest);

上面的表定义创建了一个表'testtable',其主索引或散列键变量标题为id,类型为S,表示字符串.

The above table definition creates a table 'testtable' with a main index or hash key variable titled id and the type is S for string.

此外,如果您使用继承,请确保您没有两个同名的函数相互覆盖.Dynamo 将使用顶级 getter,这可能会导致问题.

Additionally, if you are using inheritance, make sure that you don't have two functions with the same name that override each other. Dynamo will use the top-level getter and this can cause issues.

这篇关于DynamoDBMappingException:没有 HASH 键的映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)