• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on enthuware answer (I)

 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following question is from enthuware:


The correct answer is b)

Option a) is explained to be incorrect because it is not required that Address implements Serializable.
Unfortunately no explanation is given why Address must be annotated with @Embeddable.

In fact, JPA doesn't require each user defined type of a persistent field to be annotated with @Embeddable.

In my opinion either a) and b) are valid options to make the code work. For, according to JPA spec 2.1.1
serializable classes are valid types for persistent fields.





 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for Embeddable classes, it is not required to implement Serializble.

Other than that Address class, can be @IdClass.

But that option is not given. As per my understanding, the given answer is correct.
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for Embeddable classes, it is not required to implement Serializble.

That's correct. But there is a second option to extract fields into a separate class other than using
embeddable classes: Just take a serializable class as type of the field (the persistence provider
then stores the serialized object in the db). And this second option is given by a).

Of course, one can't say that Address class must implement Serializable (it can also be taken to be
a non-serializable embeddable class). But similar one can't say that Address class must be
embeddable (it can also be a serializable, non-embeddable class).

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic