Reworked the same code to use Spring Data JPA