Eu tenho a seguinte entidade com um campo LocalDate transactionDate:
public class Revenue {
... (Outros campos omitidos para simplicidade)
@Column(name = "transaction_date")
private LocalDate transactionDate;
Eu quero pegar todas as receitas de um mês específico. A URI deve ser algo como: /revenue/{ano}/{mês}.
Eh possivel fazer isso com métodos de consulta do JPA out-of-the-box?
Já tentei fazer o seguinte:
@Repository
public interface RevenueRepository extends JpaRepository<Revenue, Long> {
@Query(
"SELECT r FROM revenue WHERE YEAR(r.transactionDate) = :year AND MONTH(r.transactionDate) = :month")
Page<Revenue> findByYearAndMonth(
@Param("year") int year, @Param("month") int month, Pageable pageable);
...
public interface RevenueService {
Page<RevenueDTOResponse> getByYearAndMonth(int year, int month, Pageable pageable);
...
@Service
public class RevenueServiceImpl implements RevenueService {
@Autowired private RevenueRepository revenueRepository;
@Override
public Page<RevenueDTOResponse> getByYearAndMonth(int year, int month, Pageable pageable) {
return revenueRepository.findByYearAndMonth(year, month, pageable).map(RevenueDTOResponse::new);
}
...
@GetMapping("/{year}/{month}")
public ResponseEntity<Page<RevenueDTOResponse>> getByYearAndMonth(
@PathVariable int year, int month, Pageable pageable) {
return new ResponseEntity<>(
revenueService.getByYearAndMonth(year, month, pageable), HttpStatus.OK);
}
Mas a seguinte exceção estava sendo lançada: https://gist.github.com/davisaints/764515ff10d2113afd41844df3695a37