1Z0-900 · Question #39
When should a JPA entity implement the Serializable interface?
The correct answer is D. when JPA entities are used as parameters or return values by the remote EJB operations. Implementing Serializable is required when a JPA entity is passed as a parameter or returned from a remote EJB method, because remote calls use Java's serialization mechanism to marshal objects across the network (or JVM boundaries). Option A is wrong because the EJB Full…
Question
When should a JPA entity implement the Serializable interface?
Options
- Awhen JPA entities are used in the EJB Full container
- Bwhen JPA entities are used outside of the EJB Lite container
- Calways, because JPA entities are required to implement the Serializable interface
- Dwhen JPA entities are used as parameters or return values by the remote EJB operations
How the community answered
(27 responses)- A7% (2)
- B19% (5)
- C4% (1)
- D70% (19)
Explanation
Implementing Serializable is required when a JPA entity is passed as a parameter or returned from a remote EJB method, because remote calls use Java's serialization mechanism to marshal objects across the network (or JVM boundaries). Option A is wrong because the EJB Full container doesn't inherently mandate serialization - it's the remote interface that does. Option B inverts the logic; being "outside the EJB Lite container" is not a defined trigger for serialization. Option C is wrong because JPA itself makes no such requirement - the JPA spec explicitly states that entities should implement Serializable only if they need to be detached and passed around remotely, not universally.
Memory tip: Think "remote = serialize." Remote EJB calls cross a boundary that Java can't bridge without serialization, so any entity that travels over that wire must be serializable. If it stays local, it doesn't need to be.
Topics
Community Discussion
No community discussion yet for this question.