Page 1 of 1

About Question enthuware.oce-jpad.v6.2.548 :

Posted: Fri Mar 16, 2012 4:01 pm
by M_Z
I disagree with existing answers:

1) I selected option A as correct. Although it's not clear if the Employee is detached and sent via network, it's fine.

2) I disagree with option B, which says if Address marked as Embeddable, then Employee valid entity. To be a valid entity, Employee also must mark addr with @Embedded. Otherwise application will fail.

3) I selected option D as correct, because Employee in current state is invalid - Address is not a basic type (persistence provider does not know how to process by default), so to make it persistable we must give some idea to persistene provider, one of the possible ways - make Address serializable (we don't know it from question, but based on option A we can assume that Employee and Address will be serializable) and annotate with @Lob. Option D is more realistic than option B, because option B clearly invalid without mentioning @Embedded.

My choice is options A and D.

Re: About Question enthuware.oce-jpad.v6.2.548 :

Posted: Fri Mar 16, 2012 4:07 pm
by M_Z
To make it a bit clear: Java type for a @Lob mapping can be any serializable type

Re: About Question enthuware.oce-jpad.v6.2.548 :

Posted: Fri Mar 16, 2012 5:15 pm
by admin
You are right. Option 2 is now modified to:
This class can be made a valid entity by annotating Address class with @Embeddable and annotating addr field with @Embedded.
Option D is now incorrect because annotating it with @Lob is not a must.

thank you for your feedback!

Re: About Question enthuware.oce-jpad.v6.2.548 :

Posted: Wed Mar 25, 2015 5:48 am
by stiekemaj
M_Z wrote:I disagree with existing answers:
2) I disagree with option B, which says if Address marked as Embeddable, then Employee valid entity. To be a valid entity, Employee also must mark addr with @Embedded. Otherwise application will fail.
This is not true. The @Embedded annotation is optional. See the jpa 2.0 specs, paragraph 2.8:
If a persistent field or property other than a relationship property is not annotated with one of the map- ping annotations defined in Chapter 11 (or equivalent mapping information is not specified in the XML descriptor), the following default mapping rules are applied in order:
  • If the type is a class that is annotated with the Embeddable annotation, it is mapped in the same way as if the field or property were annotated with the Embedded annotation. See Sec- tions 11.1.13 and 11.1.14.