0

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 :

Riadh
  • 1,088
  • 2
  • 12
  • 25
  • "transient" is nothing to do with persistence ... it is to prevent serialisation and nothing else. "persistence" != "serialisation" – Neil Stockton Oct 26 '16 at 06:30

1 Answers1

0

You should use transient, according to the specification

Trigon219
  • 149
  • 1
  • 4
  • 1
    @Transient is used to persisting, and not for a serialization this is that i want to say when talk about specification, you ask for serialization. – Trigon219 Oct 25 '16 at 21:46
  • Well @Trigon219, but I you said in the attached image, I'm looking for persistence in database... And both gave the same result.. no column is generated for corresponding fields... – Riadh Oct 25 '16 at 21:52
  • 1
    Ok so, if you want the field don`t be persist, then use @Transient even this is more related with the JPA framework, that is you are using. – Trigon219 Oct 25 '16 at 21:59
  • Any detailed reason for that? – Riadh Oct 25 '16 at 22:13
  • http://stackoverflow.com/questions/2154622/why-does-jpa-have-a-transient-annotation – Trigon219 Oct 25 '16 at 22:27