Spring data @Query joda datetime postgresql исключение - PullRequest
0 голосов
/ 05 июня 2018

У меня есть сущность с 2 столбцами с joda DateTime.

@Column(name = "track_start", columnDefinition= "TIMESTAMP WITH TIME ZONE")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime start;

@Column(name = "tracke_end", columnDefinition= "TIMESTAMP WITH TIME ZONE")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime end;

Затем у меня есть хранилище данных Spring с методом поиска:

@Query("SELECT tt FROM Timetrack tt "
        + "WHERE (:dateFrom is null OR tt.start >= :dateFrom) "
        + "AND (:dateTo is null OR tt.end <= :dateTo)")
Page<Timetrack> findBy(@Param("dateFrom") DateTime dateFrom,
                       @Param("dateTo") DateTime dateTo,
                       Pageable pageable);

Если я вызываю этот метод поискаУ меня есть исключение:

org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $2
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)

Если я изменю @Param на Date вместо DateTime, я получу это исключение:

java.lang.IllegalArgumentException: Parameter value [Fri Jun 01 19:26:44 CEST 2018] did not match expected type [org.joda.time.DateTime (n/a)]
at org.hibernate.jpa.spi.BaseQueryImpl.validateBinding(BaseQueryImpl.java:897)
at org.hibernate.jpa.internal.QueryImpl.access$000(QueryImpl.java:61)

Так у кого-нибудь есть идея?

Вот вывод журнала из спящего режима:

Hibernate: select timetrack0_.id as id1_6_, timetrack0_.created as created2_6_, timetrack0_.entity_status as entity_s3_6_, timetrack0_.updated as updated4_6_, timetrack0_.user_identity_id as user_ide9_6_, timetrack0_.tracke_end as tracke_e5_6_, timetrack0_.frozen_at as frozen_a6_6_, timetrack0_.invoice_id as invoice10_6_, timetrack0_.project_id as project11_6_, timetrack0_.track_start as track_st7_6_, timetrack0_.task as task8_6_ from timetrack timetrack0_ where ( timetrack0_.entity_status = 'active') and (? is null or timetrack0_.track_start>=?) and (? is null or timetrack0_.tracke_end<=?) order by timetrack0_.track_start asc limit ? offset ?
2018-06-09 21:32:05.804 TRACE 14006 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [TIMESTAMP] - [2018-06-09 20:32:05.604]
2018-06-09 21:32:05.806 TRACE 14006 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [2] as [TIMESTAMP] - [2018-06-09 20:32:05.604]
2018-06-09 21:32:05.808 TRACE 14006 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [3] as [TIMESTAMP] - [2018-06-10 02:32:05.604]
2018-06-09 21:32:05.809 TRACE 14006 --- [           main] o.h.type.descriptor.sql.BasicBinder      : binding parameter [4] as [TIMESTAMP] - [2018-06-10 02:32:05.604]
...