nerdexam
Oracle

1Z0-900 · Question #21

Given the code fragments: Which action completes this composite primary key implementation?

The correct answer is D. Add @Embeddable annotation at line 1 and @EmbeddedId(ContactId.class) at line 2.. Option D correctly implements the @EmbeddedId composite key strategy: @Embeddable must annotate the ContactId class (marking it as an embeddable value type that JPA can map), while @EmbeddedId on the entity's ContactId field tells JPA that this single embedded object represents t

Manage Persistence using JPA Entities and BeanValidation

Question

Given the code fragments:

Which action completes this composite primary key implementation?

Exhibit

1Z0-900 question #21 exhibit

Options

  • AAdd @IdClass annotation at line 1.
  • BAdd @Embeddable annotation at line 1 and replace both @Id annotations with @EmbeddedId
  • CAdd @IdClass(ContactId.class) annotation at line 2.
  • DAdd @Embeddable annotation at line 1 and @EmbeddedId(ContactId.class) at line 2.

How the community answered

(17 responses)
  • A
    12% (2)
  • B
    6% (1)
  • D
    82% (14)

Explanation

Option D correctly implements the @EmbeddedId composite key strategy: @Embeddable must annotate the ContactId class (marking it as an embeddable value type that JPA can map), while @EmbeddedId on the entity's ContactId field tells JPA that this single embedded object represents the full composite key. Together, these two annotations form a complete and valid implementation.

Why the distractors fail:

  • A is wrong because @IdClass belongs on the entity class (line 2), not the ID class (line 1), and even then it requires @Id on each individual key field in the entity.
  • B is wrong because @EmbeddedId replaces the single ContactId field in the entity - you don't annotate multiple @Id fields; those belong to the @IdClass strategy, not @EmbeddedId.
  • C is wrong because @IdClass(ContactId.class) alone is insufficient - the entity still needs @Id on each individual key field, and the ContactId class must have matching fields (no @Embeddable needed for this approach, but more annotations are required).

Memory tip: Think EMBEDdable → EMBEDdedId - if the key class is @Embeddable, the entity field must be @EmbeddedId. If you see @IdClass, look for individual @Id annotations on the entity fields instead.

Topics

#Composite Primary Key#JPA Annotations#@EmbeddedId#Entity Design

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice