• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enthuware question com.enthuware.ets.scbcd.v5.2.69

 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following entity class:

@Entity
public class Employee{
@Id int id;
String name;
Address addr;
}

Which of the following options are correct regarding the above code ...

a) Address class must implement Serializable.
b) Address class must be annotated with @Embeddable
c) Address class must be annotated with @Entity
d) The addr field must be annotated with @Lob.

The answer given is b), which is correct. The specs read (2.1.6 Mapping Defaults for Non-Relationship Fields or Properties, page 21/22):

If a persistent field or property other than a relationship property is not annotated with one of the map-
ping annotations defined in Chapter 9 (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 9.1.34 and 9.1.35.

which explains why b) is correct. But


If the type of the field or property is one of the following, it is mapped in the same way as it
would if it were annotated as Basic: Java primitive types, wrappers of the primitive types,
java.lang.String, java.math.BigInteger, java.math.BigDecimal,
java.util.Date, java.util.Calendar, java.sql.Date, java.sql.Time,
java.sql.Timestamp, byte[], Byte[], char[], Character[], enums, any other
type that implements Serializable. See Sections 9.1.18 through 9.1.21.


So, in my opinion, if the Address class implements serializable, and is NOT annotated Embeddable, it would also work, but store the property as a blob. So, a) would also be valid, wouldn't it?

What are you opinions?
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. See also the following link
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3753
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your feedback! You are right. It is has been fixed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic