0

I have the following entity:

@Entity
public class A implements Serializable {

    @EmbeddedId
    private AId id;

    ...

    public static class AId implements Serializable {

        @Column
        private LocalDate date;

        @Column
        private String description;

    }

}

I'm trying to get all the A with a specific date. For that, I have created the following repository:

public interface ExchangeRateRepository extends JpaRepository<A, A.AId> {

    Optional<ExchangeRate> findByIdDate(LocalDate date);

}

However, this method always returns Optional.empty(). I'm using Hibernate 5.4, so compatibility issues with java.time should be fixed... I don't know what to do

EDIT #1

The generated query is the following:

select id, date, description from a where date=?
2023-03-14 11:00:08.514 TRACE 2148 --- [main] o.h.type.descriptor.sql.BasicBinder: binding parameter [1] as [DATE] - [2023-03-13]
thmasker
  • 406
  • 1
  • 9
  • 21
  • 2
    Shouldn't the method name be `findByDate` instead of `findByIdDate`? – Tarmo Mar 13 '23 at 16:13
  • 1
    But if you are sure that your method names and syntax adds up then enable debug logs and see what kind of SQL with what kind of params is produced. This should tell you why nothing is returned. https://stackoverflow.com/questions/30118683/how-can-i-log-sql-statements-in-spring-boot – Tarmo Mar 13 '23 at 16:18
  • Do you marked your repo as @Repository? – coman Mar 13 '23 at 16:23
  • 2
    @coman that is irrelevant and unnecessary. – Jens Schauder Mar 14 '23 at 07:55
  • @Tarmo since I'm using `@EmbeddedId` the property is `id.date`, so it is `findByIdDate`. The sql query is correctly formed – thmasker Mar 14 '23 at 09:51

0 Answers0