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

我的课程如下


@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 获取结果 但不知何故它导致了异常 有人可以看到我做错了什么吗


江户川乱折腾
浏览 397回答 2
2回答

心有法竹

您的异常消息说@DynamoDBIndexHashKey&nbsp;must&nbsp;specify&nbsp;one&nbsp;of&nbsp;HASH&nbsp;GSI&nbsp;name/names如果您查看类中的所有@DynamoDBIndexHashKey注释,您会发现它们都设置了一个值,globalSecondaryIndexName除了 上的注释eventType。如果eventType应该是 GSI 哈希键,则需要设置此值。如果eventType不应该是 GSI 的哈希键,那么您需要@DynamoDBIndexHashKey从该字段中删除注释。有关使用的更多详细信息,请参阅javadoc@DynamoDBImdexHashKey。

肥皂起泡泡

它必须是这样的:@get:DynamoDBIndexHashKey(attributeName = "product", globalSecondaryIndexName = "product-index")var product: String? = null将此也添加到数据库定义中:CreateTableRequest()&nbsp;...&nbsp;.withGlobalSecondaryIndexes(GlobalSecondaryIndex()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .withIndexName(PRODUCT_INDEX)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .withKeySchema(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KeySchemaElement(PRODUCT, KeyType.HASH),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KeySchemaElement(PRODUCT_RANGE, KeyType.RANGE))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .withProjection(Projection().withProjectionType(ProjectionType.ALL))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .withProvisionedThroughput(ProvisionedThroughput(1L, 2L)))&nbsp;&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java