The annotation @Transient
can be used in the attribute of a class, or in a method get
, in your case getIdValidacao()
. The way it is established is related to a class annotation, being @Access(AccessType.FIELD)
to be in an attribute, or @Access(AccessType.PROPERTY)
for method.
Unlike this, but serving the same purpose, there is one of the reserved words of the Java language, the transient
, and it has no relation to the JPA specification, but to the interface java.io.Serializable
.
When a class is flagged with this interface, something mystical happens, methods not shown in the interface signature, writeObject(ObjectOutputStream)
and readObject(ObjectInputStream)
, appear without your consent to a possible serialization, but what is this?
Although using JPA in your project, use transient
can help you relieve the storage of objects in memory while running @Stateful
Enterprise Java Beans (EJB), or even Contexts and Dependency Injection (CDI) scopes other than @RequestScoped
, because the purpose of serialization itself is to store files in memory, even if they are not being used, as in this scenario, or for a possible record in files.
It is important to inform a serialVersionUID
so that the objects in memory, the Pojos, do not get confused on their own, and when saving them in file, it is recommended to use a Serialization Proxy, mentioned by Joshua Bloch in the book Effective Java.