Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override audit field @CreatedDate

Tags:

How to over ride audit field having @CreatedDate. if value is not set for audit field @CreatedDate should be applied other wise it should take the value that has been set. Is there any feature to enable in spring JPA.

like image 737
Vaidya Avatar asked May 12 '16 09:05

Vaidya


1 Answers

It's not elegant, but if you want to reset the value of the @CreatedDate field, you can save the entity after the initial save with any date you like:

  // creates entity
  repository.save(entity);

  // overwrite created date on the entity
  entity.setCreatedDate(getSomeCreatedDate());

  // re-save the entity
  repository.save(entity);
like image 165
Jan Nielsen Avatar answered Sep 28 '22 02:09

Jan Nielsen