I have the following code in my entity class
@CreationTimestamp
@Column(updatable = false)
private LocalDate dateAdded;
@JsonProperty("last_edited")
@UpdateTimestamp
@Column(updatable = false)
private LocalDate lastEdited;
However, when it comes to posting to the database, I am only getting null values for the two columns.
I am using Java 18 and spring-boot-starter-jpa
Edit: haven't figured out what's causing the problem... going to add the local date in the service instead for now...
var sql = """
INSERT INTO public.recipe ("name", "instructions", "date_added", "last_edited")
VALUES (?, ?, ?, ?)
""";
LocalDateTime localDateTime = LocalDateTime.now();
recipeDTO.setDateAdded(localDateTime);
recipeDTO.setLastEdited(localDateTime);
jdbcTemplate.update(
sql,
recipeDTO.getName(),
recipeDTO.getInstructions(),
localDateTime,
localDateTime
);


You have to remove the
updatable = falsepart as Hibernate will exclude assignments to these columns in update statements. So even if you do update the entity fields, the data will not be updated in the database.