Hibernate JPA @UpdateTimestamp Example

@UpdateTimestamp

The @UpdateTimestamp annotation is used to specify that the currently annotated timestamp attribute should be updated with the current JVM timestamp whenever the owning entity gets modified.

java.util.Date

java.util.Calendar

java.sql.Date

java.sql.Time

java.sql.Timestamp


UpdateTimestamp marks a property as the update timestamp of the containing entity. The property value will be set to the current VM date whenever the owning entity is updated.
Supported property types:


  • Date
  • Calendar
  • Date
  • Time
  • Timestamp
  • Instant
  • LocalDate
  • LocalDateTime
  • LocalTime
  • MonthDay
  • OffsetDateTime
  • OffsetTime
  • Year
  • YearMonth
  • ZonedDateTime


@UpdateTimestamp annotation
The @UpdateTimestamp annotation instructs Hibernate to set the annotated entity attribute with the current timestamp value of the JVM when the entity is being persisted.

The supported property types are:


  • java.util.Date

  • java.util.Calendar

  • java.sql.Date

  • java.sql.Time

  • java.sql.Timestamp


Example : @UpdateTimestamp mapping example

@Entity(name = "Bid")
public static class Bid {

@Id
@GeneratedValue
private Long id;

@Column(name = "updated_on")
@UpdateTimestamp
private Date updatedOn;

@Column(name = "updated_by")
private String updatedBy;

private Long cents;

//Getters and setters are omitted for brevity

}

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation