I have tried make a different method in Spring Data JPA Repository which should adding the given hours to timestamp.
public interface ActivationCodeRepository extends CrudRepository<ActivationCode, Long> {
@Query(value = "select a from ActivationCode a where a.creationTime + INTERVAL '1 hour' * :hoursAgo <= CURRENT_TIMESTAMP and a.type = :type and a.account = account")
List<ActivationCode> getAllAddedAtLeastXHoursAgo(@Param("account") Account account, @Param("type") int type, @Param("hoursAgo") int hoursAgo);
}
It is not working because of it:
- INTERVAL '1 hour' * :hoursAgo
exactly:
'1 hour'
The IDE underscores and given this error:
<'expression'>, <'operator'>, GROUP, HAVING or ORDER expected.
I have tried do some research and find how exactly I should adding the given hours to the creationTime but not found anywhere.