gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:57:03 45 4
gpt4 key购买 nike

我的类(class)如下

@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);

尽管插入工作正常,但在获取结果期间我遇到了异常

com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: @DynamoDBIndexHashKey must specify one of HASH GSI name/names
at com.amazonaws.services.dynamodbv2.datamodeling.StandardAnnotationMaps$FieldMap.globalSecondaryIndexNames(StandardAnnotationMaps.java:345) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperFieldModel$Properties$Immutable.<init>(DynamoDBMapperFieldModel.java:459) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardBeanProperties$Bean.<init>(StandardBeanProperties.java:92) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardBeanProperties$Bean.<init>(StandardBeanProperties.java:86) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardBeanProperties$BeanMap.putOrFlatten(StandardBeanProperties.java:217) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardBeanProperties$BeanMap.putAll(StandardBeanProperties.java:207) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardBeanProperties$BeanMap.<init>(StandardBeanProperties.java:198) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardBeanProperties$CachedBeans.getBeans(StandardBeanProperties.java:55) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardBeanProperties$CachedBeans.access$100(StandardBeanProperties.java:48) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardBeanProperties.of(StandardBeanProperties.java:42) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardModelFactories$TableBuilder.<init>(StandardModelFactories.java:132) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardModelFactories$TableBuilder.<init>(StandardModelFactories.java:116) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.StandardModelFactories$StandardTableFactory.getTable(StandardModelFactories.java:107) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.getTableModel(DynamoDBMapper.java:393) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.createQueryRequestFromExpression(DynamoDBMapper.java:1626) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.query(DynamoDBMapper.java:1503) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.amazonaws.services.dynamodbv2.datamodeling.AbstractDynamoDBMapper.query(AbstractDynamoDBMapper.java:265) ~[aws-java-sdk-dynamodb-1.11.172.jar:na]
at com.furlenco.platform.loggingservice.service.impl.LogServiceimpl.getLogsBasedOnSecondaryIndexUserId(LogServiceimpl.java:86) ~[classes/:na]
at com.furlenco.platform.loggingservice.service.impl.LogServiceimpl.getEventLogsForUserId(LogServiceimpl.java:67) ~[classes/:na]

我有一个表,其中散列键为交互服务,范围键为 CreatedDate。我正在尝试通过 GSI 获取结果,但不知何故它导致了异常有人可以看看我做错了什么

最佳答案

您的异常消息显示

@DynamoDBIndexHashKey must specify one of HASH GSI name/names

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

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

关于java - @DynamoDBIndexHashKey 必须指定 HASH GSI 名称之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51642859/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com