Vercelの環境変数を設定する画面

Attempt to execute an operation that requires a primary index...の解消方法

公開日:

更新日:

エラーの原因 :getter/setterの名称がフィールド名と異なってしまっていた。

 

① 発生したエラー

AWS SDK v2 for Java’s DynamoDB Enhanced Clientを利用しているアプリで下記のエラーが発生しました。

AWS CloudWatchで確認したエラー

1<clinit> Initialize error : A MultiException has 4 exceptions.
2They are:\n1. java.lang.IllegalArgumentException: Attempt to execute an operation
3that requires a primary index without defining any primary key attributes in the table metadata.\n2.
 

② エラーの原因はgetterの名前がフィールドと一致していなかったミス

コードを調べていくうちに下記のようにフィールド変数の名称とgetterの名称に差異がありそこでエラーとなっていることが判明しました。

フィールド変数はsampleなのでgetSampleが正しいです。

これはgetExampleになってしまっています。

DynamoDB用Beanクラス

1
2// DynamoDB項目
3private String sample;
4
5/**
6 * getSample
7 * 
8 * @return the sample
9 */
10@DynamoDbPartitionKey
11@DynamoDbAttribute("Sample")
12public String getExample() {
13	return sample;
14}
15
16/**
17 * setSample
18 * 
19 * @param sample the sample to set
20 */
21public void setSample(String sample) {
22	this.sample = productOwnId__fileName;
23}

上記のずれを直すと無事エラーが消えました。

下記の記事をエラー解消にあたって参考にさせて頂いたので共有します。

DynamoDB Enhanced Client for Java: Missing Setters Cause Misleading Error or Unexpected Behavior

以上になります。

お役に立てましたら幸いです。

ご一読頂きありがとうございました。