Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does JPA have a @Transient annotation?

Java has the transientkeyword. Why does JPA have @Transient instead of simply using the already existing java keyword?

like image 246
deamon Avatar asked Jan 28 '10 13:01

deamon


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

What is the use of @transient annotation in spring boot?

@Transient annotation is used to mark a field to be transient for the mapping framework, which means the field marked with @Transient is ignored by mapping framework and the field not mapped to any database column (in RDBMS) or Document property (in NOSQL). Thus the property will not be persisted to data store.

What does @transient do in Java?

Transient in Java is used to mark the member variable not to be serialized when it is persisted to streams of bytes. This keyword plays an important role to meet security constraints in Java. It ignores the original value of a variable and saves the default value of that variable data type.

Is @column annotation necessary?

@Column. Let's start with the @Column annotation. It is an optional annotation that enables you to customize the mapping between the entity attribute and the database column.


1 Answers

Java's transient keyword is used to denote that a field is not to be serialized, whereas JPA's @Transient annotation is used to indicate that a field is not to be persisted in the database, i.e. their semantics are different.

like image 119
Jawher Avatar answered Oct 04 '22 10:10

Jawher