What should be done to ensure that a field in an entity class is NOT persisted to the database?
a) make it transient using the transient keyword
b) Annotate it with @NotPersistent
c) Annotate it with @Transient
d) Do not annotate it with @Persistent
e) Use transient keyword as well as annotate it with @NotPersistent.
The answer they give is c), this is correct. But I think a) is also correct? Their explanation why a) is incorrect is:
Transient keywork only prevents file I/O serialization. It is not useful in this case.
but here is an excerpt from the specs (2.1.1 Persistent fields and properties, page 18):
If the entity has ﬁeld-based access, the persistence provider runtime accesses instance variables
directly. All non-transient instance variables that are not annotated with the Transient
annotation are persistent. When ﬁeld-based access is used, the object/relational mapping anno-
tations for the entity class annotate the instance variables.
Mapping annotations cannot be applied to ﬁelds or properties that are transient or Tran-
What do you ranchers think?
Enthuware Software Support
posted 8 years ago
From the section of the specification that you've referred, it seems clear that even making the field trasient will work. So I think it should be fixed