Camilo Morales<br />SCJP 5, SCBCD 5
Originally posted by Camilo Morales:
13). Given an excerpt of a Book entity (it is just missing the import
statements):
10. @Entity
11. public class Book implements Serializable {
12. @Id
13. @GeneratedValue(strategy = GenerationType.AUTO)
14. private Integer id;
15. String bookName;
16. protected int price;
17. enum Status {IN, OUT};
18. @Enumerated( EnumType.ORDINAL )
19. Status status;
20. transient int bar;
21. java.util.Map<Integer, String> comments;
22. protected Book() {};
23. }
No descriptors are used.
Which statement is correct about this entity?
A) There is an error on line 11. It must NOT implement Serializable.
B) Adding a single @Transient annotation makes this entity valid.
C) The visibility declarations on some of the variables causes an
exception.
D) The enumeration or its field definition on lines 17, 18, or 19 is
NOT valid.
E) There is an error in the identity definition on lines 12, 13, or
14.
After the check list I can discard A and C but not sure about the
rest.
/** Code speaks louder than words */
SCJP5 | SCBCD5 | SCEA5 Part 1
Camilo Morales<br />SCJP 5, SCBCD 5
Camilo Morales<br />SCJP 5, SCBCD 5
/** Code speaks louder than words */
Camilo Morales<br />SCJP 5, SCBCD 5
SCJP5 | SCBCD5 | SCEA5 Part 1
Collection-valued persistent fields and properties must be defined in terms of one of the following collection-
valued interfaces regardless of whether the entity class otherwise adheres to the JavaBeans
method conventions noted above and whether field or property-based access is used:
java.util.Collection, java.util.Set, java.util.List[4], java.util.Map.[5]
...
[4] Portable applications should not expect the order of lists to be maintained across persistence contexts unless the OrderBy construct
is used and the modifications to the list observe the specified ordering. The order is not otherwise persistent.
[5] The implementation type may be used by the application to initialize fields or properties before the entity is made persistent; subsequent
access must be through the interface type once the entity becomes managed (or detached).
The persistent fields or properties of an entity MAY BE of the following types:
*
Java primitive types
*
java.lang.String
*
other Java serializable types (including wrappers of the primitive types, java.math.BigInteger, java.math.BigDecimal, java.util.Date, java.util.Calendar, java.sql.Date, java.sql.Time, java.sql.Timestamp, user-defined serializable types, byte[], Byte[], char[], and Character[])
*
enums
*
entity types and/or collections of entity types
*
embeddable classes
Camilo Morales<br />SCJP 5, SCBCD 5
Anyway I didnt FIND that explanation in the Specs or in the MZ notes ... I guess that if we are right ... they assumed we will never use Collection types for non-relationships persistent fields.
Camilo Morales<br />SCJP 5, SCBCD 5
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|