Using Spring Data we were facing the same issue with sql server
We solved it using
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
@Generated(GenerationTime.INSERT)
@Column(name = "created", insertable = false, updatable = false)
private LocalDateTime created;
You can combine it saveAndFlush (From JpaRepository)
If nothing works you can either implement refresh method by extending SimpleJpaRepository
or avoid using the database default and replace it with an EntityListener
@EnableJpaAuditing
public class ConfigClass {...}
@EntityListeners(AuditingEntityListener.class)
public class YourEntity {
@Column(name = "created", insertable = false, updatable = false)
@CreatedDate
private LocalDateTime created;
}
Take in consideration that using EntityListener you have to remove the database default. You could set insertable=true and use ColumnTransformer
@Column(name = "created", updatable = false)
@ColumnTransformer(write = "coalesce(sysutcdatetime(), ?)")
@CreatedDate
private LocalDateTime created;