1
I’m learning to play with Javax, and persistence of Java and I want to know if there’s any way to leave a default value for the database.
Example in SQL:
variacao TIMESTAMP DEFAULT CURRENT_TIMESTAMP
How would I do that in my Template code ?
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private int id;
@NotNull
@Column(name="nota")
private int nota;
@NotNull
@Column(name="data")
private Timestamp data;
@Column(name="comentario")
private String comentario;
@Column(name="evento_id")
private Evento evento_id;
@Column(name="pessoa_id")
private Pessoa pessoa_id;
1) What is the difference between the following items? a) @Defaultvalues b) @Prepersistent c) @Preupdate
2) And which one would I use for this case ? a) @Defaultvalues b) @Prepersistent c) @Preupdate
What is Defaultvalue for? And also, as I saw Prepersist and Preupdate are methods, correct ?
– Felipe Junges
@Felipejunges Yes, Voce puts
@PrePersist
and@PreUpdate
in a method and within it you change the values of Entity as you like. The annotationDefaultValue
there is no– deFreitas