I am using Hibernate with a Postgres DB and have a problem with the following query:
@Query("Select l from Leasing l where l.user = :user " +
" and (:fromDate is null or l.from >= :fromDate)")
Page<Leasing> findAllByUserAndStatusAndFromAndTo(Pageable pageable, @Param("user") User user,
@Param("fromDate") Instant from);
I got the error message:
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $2
The field is defined like this:
@Column(name = "from_time")
@NotNull
private Instant from;
I know this is a problem with Postgres, because in the test-environment an H2 database is used and it worked fine.
In the postgres database the datatype of the field is: timestamp without time zone
I tried to use LocalDateTime instead of Instant but it didn't work either.
EDIT:
If I remove :fromDate is null
it works, but I need this check?