【发布时间】:2020-08-12 08:44:22
【问题描述】:
实际数据库表:
Column | Type | Collation | Nullable | Default
--------+-----------+-----------+----------+---------
room | text | | |
during | daterange | | |
工作数据库查询:
select * from room_reservation where during && daterange('[2020-10-15,2020-11-14)');
实体映射:
@Column(name = "during", columnDefinition = "daterange")
private Range<Date> during;
Jpa 存储库:
@Query(value = "select r.room from Room_Occupancy r where r.during && daterange('[?1, ?2)')", nativeQuery = true)
List<Long> findOccupiedRooms(@Param("d1") Date d1, @Param("d2") Date d2);
例外:
Caused by: org.postgresql.util.PSQLException: ERROR: invalid input syntax for type date: "?1"
Position: 65
如何在 JPA 中编写相同的查询?
【问题讨论】:
标签: spring postgresql spring-boot spring-data-jpa