1Z0-900 · Question #47
Which of these can be a JPA entity?
The correct answer is A. Enum type. There appears to be an error in the provided answer key - the correct answer is actually B (Abstract class), not A. Why B is correct: The JPA specification explicitly allows abstract classes to be entities. Abstract entity classes are common in inheritance hierarchies (e.g…
Question
Which of these can be a JPA entity?
Options
- AEnum type
- BAbstract class
- CInterface type
- DFinal class
How the community answered
(38 responses)- A92% (35)
- B3% (1)
- C5% (2)
Explanation
There appears to be an error in the provided answer key - the correct answer is actually B (Abstract class), not A.
Why B is correct: The JPA specification explicitly allows abstract classes to be entities. Abstract entity classes are common in inheritance hierarchies (e.g., using @Inheritance), and they follow all the same rules as concrete entity classes - they can have @Id, mappings, and be queried via JPQL.
Why the others are wrong:
- A (Enum): The JPA spec explicitly states "An enum or interface may not be designated as an entity." Enums can be fields of an entity (via
@Enumerated), but not entities themselves. - C (Interface): Also explicitly prohibited by the JPA spec alongside enums.
- D (Final class): JPA entities must not be final, because JPA providers (like Hibernate) generate proxies by subclassing the entity at runtime - final classes cannot be subclassed.
Memory tip: Think "JPA needs to subclass your entity to create proxies." That immediately rules out final classes, interfaces, and enums (none can be subclassed/extended in the usual way). Only a regular or abstract class works - and abstract is fine because JPA just needs a class.
Heads up: The answer key you received marks A as correct, but per the JPA 2.x specification, B is the right answer. This may be a typo in the source material.
Topics
Community Discussion
No community discussion yet for this question.