nerdexam
Oracle

1Z0-900 · Question #22

Given the code fragment: How can you apply DateConverter to the birthday field?

The correct answer is A. by adding @Convert(to=Date.class) at line 3. Applying @Convert(converter=DateConverter.class) directly on the birthday field (line 3) is the correct JPA approach - it tells the persistence provider to use that specific AttributeConverter implementation when reading/writing that field to the database. Why the distractors…

Manage Persistence using JPA Entities and BeanValidation

Question

Given the code fragment:

How can you apply DateConverter to the birthday field?

Exhibit

1Z0-900 question #22 exhibit

Options

  • Aby adding @Convert(to=Date.class) at line 3
  • Bby invoking the setConverter(DateConverter.class) method on the EntityManager object
  • Cby adding @Converter(autoApply=true) at line 1
  • Dby adding @Convert((DateConverter.class)) at line 2

How the community answered

(34 responses)
  • A
    85% (29)
  • B
    9% (3)
  • C
    3% (1)
  • D
    3% (1)

Explanation

Applying @Convert(converter=DateConverter.class) directly on the birthday field (line 3) is the correct JPA approach - it tells the persistence provider to use that specific AttributeConverter implementation when reading/writing that field to the database.

Why the distractors are wrong:

  • B is wrong because EntityManager has no setConverter() method; JPA converters are wired declaratively via annotations, not programmatically.
  • C is wrong in intent: @Converter(autoApply=true) belongs on the converter class itself (line 1), not the field - and it applies globally to all compatible types, not selectively to birthday.
  • D is wrong due to invalid syntax; @Convert requires the named attribute converter=, so the double-parenthesis form @Convert((DateConverter.class)) won't compile.

Memory tip: Distinguish the two annotations by their targets - @Converter (with an r) lives on the converter class to register it; @Convert (no r) lives on the entity field to apply it. If you see "apply to a specific field," always reach for @Convert on the field.

Topics

#JPA Converters#@Convert annotation#Entity field mapping#Date conversion

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice