I am having a POJO class which consists of:
- persistent properties,
- transient properties.
While writing HQL I considered both: persistent and transient properties.
I.e. HQL like select persistent_properties,transient_prop from Pojo_classname
is it correct?
Can I write @Basic
annotation to transient variables?
Annotation Type Transient. This annotation specifies that the property or field is not persistent. It is used to annotate a property or field of an entity class, mapped superclass, or embeddable class. Example: @Entity public class Employee { @Id int id; @Transient User currentUser; ... }
At the time of serialization, if you don't want to save the value of a particular variable in a file, then use the transient keyword. transient private <member variable>; In case you define any data member as transient, it will not be serialized. This is because every field marked as transient will not be serialized.
Annotation Type TransientMarks a field to be transient for the mapping framework. Thus the property will not be persisted and not further inspected by the mapping framework.
A variable that is initialized by its default value during de-serialization is known as a transient variable. A transient variable plays an important role in preventing an object from being serialized. We can make any variable transient by using the transient keyword.
No, it's not correct. A HQL query translates to SQL. An @Transient
property is not in the database, so the SQL query won't be able to query over this property.
@Basic
and @Transient
are contradictory. The first one tells "this property is persistent" and the second one tells "This property is not persistent".
If you're talking about the Java transient
keyword, and not about the @Transient
annotation, then yes, a transient
field may be queried and annotated with @Basic
. The transient
keyword has nothing to do with persistence, only with binary serialization of the object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With