简体   繁体   中英

Non-persisting fields: JPA '@Transient' vs Java SE 7 'transient'

Which one to use for skipping field persisting in an Entity?

@Transient is used as part of JPA to ignore a field from persisting

The transient keyword in Java is used to indicate that a field should not be serialized and persisted (Specification of Java SE 7 Edition)

I checked the both, and for the both no column is generated in the database :

The entity :

@Entity
public class Person implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id@GeneratedValue(strategy=GenerationType.IDENTITY)
    private long id;
    private String name;
    private String forname;

    @Transient
    private String nickName;

    private transient String pseudo;

The generated table :

您应根据规范使用瞬态

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM