为了账号安全,请及时绑定邮箱和手机立即绑定

@DynamoDBIndexHashKey 必须指定 HASH GSI 名称之一

@DynamoDBIndexHashKey 必须指定 HASH GSI 名称之一

江户川乱折腾 2021-06-15 17:54:18
我的课程如下@DynamoDBTable(tableName = LogConstant.TableName)public class Journal {@DynamoDBIndexHashKey(attributeName = "event_type")private String eventType;@DynamoDBIndexHashKey(attributeName = "user_id",globalSecondaryIndexName = LogConstant.GlobalUserIdIndex)private String userId;@DynamoDBIndexHashKey(attributeName = "user_identifier", globalSecondaryIndexName = LogConstant.GlobalUserIdentifierIndex)private String userIdentifier;@DynamoDBIndexHashKey(attributeName = "order_id", globalSecondaryIndexName = LogConstant.GlobalOrderIdIndex)private String orderId;@DynamoDBTypeConvertedEnum@DynamoDBAttribute(attributeName = "generated_by")private GenertionType generatedBy;@DynamoDBTypeConvertedEnum@DynamoDBHashKey(attributeName = "interacting_service")private InteractingService interactingSerice;@DynamoDBAttribute(attributeName = "agent")private String agent;@DynamoDBAttribute(attributeName = "content")private String content;@DynamoDBRangeKey@DynamoDBIndexRangeKey(attributeName = "created_at",        globalSecondaryIndexNames = {LogConstant.GlobalUserIdIndex,LogConstant.GlobalUserIdentifierIndex,LogConstant.GlobalOrderIdIndex})private String createdAt;获取搜索结果的服务是DynamoDBQueryExpression<Journal> expression = new DynamoDBQueryExpression<Journal>()            .withIndexName(LogConstant.GlobalUserIdIndex)            .withConsistentRead(false)            .withHashKeyValues(journal);    TableDescription table = DynamoDbStarter.getDynamoDB().getTable(LogConstant.TableName).describe();    return DynamoDbStarter.getDynamoDBMapper().query(Journal.class, expression);即使插入工作正常但在获取结果期间我收到异常我有一个哈希键作为interacting_service 和范围键作为CreatedDate 的表。我正在尝试通过 GSI 获取结果 但不知何故它导致了异常 有人可以看到我做错了什么吗
查看完整描述

2 回答

?
心有法竹

TA贡献1866条经验 获得超5个赞

您的异常消息说

@DynamoDBIndexHashKey must specify one of HASH GSI name/names

如果您查看类中的所有@DynamoDBIndexHashKey注释,您会发现它们都设置了一个值,globalSecondaryIndexName除了 上的注释eventType。如果eventType应该是 GSI 哈希键,则需要设置此值。如果eventType不应该是 GSI 的哈希键,那么您需要@DynamoDBIndexHashKey从该字段中删除注释。

有关使用的更多详细信息,请参阅javadoc@DynamoDBImdexHashKey


查看完整回答
反对 回复 2021-06-23
?
肥皂起泡泡

TA贡献1829条经验 获得超6个赞

它必须是这样的:


@get:DynamoDBIndexHashKey(attributeName = "product", globalSecondaryIndexName = "product-index")

var product: String? = null

将此也添加到数据库定义中:


CreateTableRequest()


 ...


 .withGlobalSecondaryIndexes(GlobalSecondaryIndex()

            .withIndexName(PRODUCT_INDEX)

            .withKeySchema(

               KeySchemaElement(PRODUCT, KeyType.HASH),

               KeySchemaElement(PRODUCT_RANGE, KeyType.RANGE))

            .withProjection(Projection().withProjectionType(ProjectionType.ALL))

            .withProvisionedThroughput(ProvisionedThroughput(1L, 2L)))  


查看完整回答
反对 回复 2021-06-23
  • 2 回答
  • 0 关注
  • 396 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号