I have an entity that has a date field annotated with @Future. I create the record/transaction initially with a given date (let's say tomorrows date 5/31/21) using repository.save(data). - Works Fine!
public class data{
@Future
private Date date;
private String status;
}
5/31/2021
data data = new data(LocalDateTime.now(), "initialstatus")
repository.save(data);
I then come in on 6/1/21 and update a different field called "status", but when I go to make the update I get an error that the transaction can't be committed, and I am guessing because it's trying to save the 5/31/21 date in the @Future date field on 6/1/21 (which is not a future date at this point) while trying to update the status field.
6/1/2021
data data = repository.findById(id).get();
data.setStatus("updatedstatus");
repository.save(data);
2021-05-30 09:46:13.597 DEBUG 10984 ---
[nio-8080-exec-9] .m.m.a.ExceptionHandlerExceptionResolver : Resolved
[org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction;
nested exception is javax.persistence.RollbackException:
Error while committing the transaction]
Once I remove the @Future, I can update the status field, so my question is how can I update just the status field and not the date field where it's failing because the date is now in the past.