Since we implemented Entity Auditing, we were able to store CreatedBy using AuditorAware also @lastmodifiedby too. But here the problem is, once we updated the record again we are trying to fetch the updated record using findbyId
but its giving @createdby
and @createddate
as null, and @lastmoidified
date also a different example in DB 2021-10-02 17:43:05
but in the response 2021-10-02T12:30:29.596038100Z
Even I got a few solutions from the web listed below
- SaveAndFlush - This will disturb the @transactional model, so we cannot use this,
Sample Code :
@GetMapping(value = "/saveandshow")
public Object GetsavedValue(@RequestParam("name") String name,@RequestParam("id") Long id ) {
//List<Account> list = accRepo.findAll();
Account acc_find = accRepo.getOne(Long.valueOf(id));
Account account = new Account();
account.setId(acc_find.getId());
account.setAccountname(name);
//account.setAge(name);
Account acc = accRepo.save(account);
Optional<Account> fetchAccount = accRepo.findById(acc.getId());
System.out.println("Accont "+fetchAccount);
return "Success";
}
am i doing something wrong ..?
ref : https://github.com/vivekjava/Audit/blob/main/src/main/java/com/vivek/rest/AccountResource.java#L37
Please provide youre thoughts or inputs, I really appreciate it.