Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotation @Basic to transient variables

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?

like image 204
Nandkumar Tekale Avatar asked Nov 25 '11 09:11

Nandkumar Tekale


People also ask

What is the use of @transient annotation?

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; ... }

How do you mark a field as transient?

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.

What is @transient annotation in spring?

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.

How do you make a variable transient?

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.


1 Answers

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.

like image 91
JB Nizet Avatar answered Oct 23 '22 10:10

JB Nizet