So, it turned out that the problem was in the multiline string literal for query.
@Query("""
SELECT
u.customerId AS customerId,
r.id.amountThreshold AS amountThreshold,
SUM(r.amount) AS amount
FROM RecordEntity r
JOIN UserEntity u ON r.id.accountNumber = u.accountNumber
WHERE u.customerId IN ?1
GROUP BY u.customerId, r.id.amountThreshold
ORDER BY u.customerId, r.id.amountThreshold
""")
Looks like Hibernate adds special characters somewhere inside and then cannot recognize aliases..