FilterDef中的LocalDateTimeType转换为bigint而不是timestamp

时间:2017-06-06 17:36:58

标签: hibernate

在我的实体类中,我有以下过滤器定义:

@FilterDefs({
    @FilterDef(name="courseStartsBetween", parameters = {
        @ParamDef(name="startDateTime", type="LocalDateTime"),
        @ParamDef(name="endDateTime", type="LocalDateTime")
    })
})
@Filters({
    @Filter(name="courseStartsBetween", condition="scope_id NOT IN (select scope_id FROM course_time_slot WHERE course_time_slot.end_date_time < :startDateTime OR course_time_slot.start_date_time > :endDateTime)")
})

基于Hibernate documentationLocalDateTime是Java 8的LocalDateTime个对象的有效BasicTypeRegistry键,并且类型映射得很好。我现在按如下方式启用过滤器:

requestContainer.entityManager().unwrap(Session.class)
        .enableFilter("courseStartsBetween")
        .setParameter("startDateTime", septemberFirst.atStartOfDay())
        .setParameter("endDateTime", septemberFirst.plus(1, ChronoUnit.YEARS).atStartOfDay());

查询片段已正确嵌入查询中(启用了show-sql),但查询失败并显示:

    Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: timestamp without time zone > bigint
    Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
        Position: 4114
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2310) ~[postgresql-9.4.1209.jar:9.4.1209]
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2023) ~[postgresql-9.4.1209.jar:9.4.1209]
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:217) ~[postgresql-9.4.1209.jar:9.4.1209]
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:421) ~[postgresql-9.4.1209.jar:9.4.1209]
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:166) ~[postgresql-9.4.1209.jar:9.4.1209]
    at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:118) ~[postgresql-9.4.1209.jar:9.4.1209]
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:71) ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
... 55 common frames omitted

这是意料之外的,因为我的字段映射到timestamp类型(根据上面引用的文档也应该这样)。我应该如何在LocalDateTime中映射FilterDef类型?

0 个答案:

没有答案