diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap index b973bf217..7a37765e7 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap @@ -468,7 +468,7 @@ public final class Project implements Model { public static final QueryField PROJECT_TEAM_NAME = field(\\"Project\\", \\"projectTeamName\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String projectId; private final @ModelField(targetType=\\"String\\", isRequired = true) String name; - private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"project\\", type = Team.class) Team team = null; + private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"project\\", targetNames = {\\"projectTeamTeamId\\", \\"projectTeamName\\"}, type = Team.class) Team team = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; private final @ModelField(targetType=\\"ID\\") String projectTeamTeamId; diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index ccf7b20e6..b9eba486d 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -1111,6 +1111,10 @@ export class AppSyncModelJavaVisitor< case CodeGenConnectionType.HAS_ONE: connectionDirectiveName = 'HasOne'; connectionArguments.push(`associatedWith = "${this.getFieldName(connectionInfo.associatedWith)}"`); + if (this.isCustomPKEnabled()) { + const hasOneTargetNamesArgs = `targetNames = {${connectionInfo.targetNames.map(target => `"${target}"`).join(', ')}}`; + connectionArguments.push(hasOneTargetNamesArgs); + } break; case CodeGenConnectionType.HAS_MANY: connectionDirectiveName = 'HasMany';