0

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?

Steve2Fish
  • 187
  • 4
  • 15
  • What data type does the column `from_time` have? `DATE`, `TIME`, `DATETIME` or anything else? Maybe it's just mixing up `from_time` (in `@Column`) and `from_date` (in `@Query`)? Those might have different types... – deHaar Dec 20 '19 at 08:52
  • Add the Jadira Usertype lib as a dependency, and you'll get additional support (see dupe for more info). – Kayaman Dec 20 '19 at 08:57

0 Answers0