Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 由于bytea强制转换错误,使用Kotlin nullable类型时本机JPA查询不起作用_Hibernate_Jpa_Kotlin_Spring Data Jpa_Spring Data - Fatal编程技术网

Hibernate 由于bytea强制转换错误,使用Kotlin nullable类型时本机JPA查询不起作用

Hibernate 由于bytea强制转换错误,使用Kotlin nullable类型时本机JPA查询不起作用,hibernate,jpa,kotlin,spring-data-jpa,spring-data,Hibernate,Jpa,Kotlin,Spring Data Jpa,Spring Data,我正在使用Kotlin、springboot和springdata与Hibernate和Postgresql 我们创建了一个repository类,它扩展了JpaRepository,刚刚发现如果提供了null参数,本机查询将无法工作 在本例中,isInternal参数可以是true、false或null,如果我们还不知道这些信息(与数据库中的相同) 如果我们尝试添加显式强制转换,错误就会改变 @Query( nativeQuery = true, val

我正在使用
Kotlin
springboot
springdata
Hibernate
Postgresql

我们创建了一个repository类,它扩展了
JpaRepository
,刚刚发现如果提供了null参数,本机查询将无法工作

在本例中,
isInternal
参数可以是true、false或null,如果我们还不知道这些信息(与数据库中的相同)

如果我们尝试添加显式强制转换,错误就会改变

    @Query(
        nativeQuery = true,
        value = "SELECT * FROM story WHERE is_internal = CAST(:isInternal AS boolean)",
        countQuery = "SELECT COUNT(*) FROM story WHERE is_internal = CAST(:isInternal AS boolean)"
    )
    fun findEmployeeStories(
        @Param("isInternal") isInternal: Boolean?,
        pageable: Pageable
    ): Page<StoryEntity>
如果我们将
@Param(“isInternal”)isInternal:Boolean?
更改为
@Param(“isInternal”)isInternal:Boolean
(禁止可为空的值),它可以正常工作,但我们不希望这样

以上只是一个简单的例子来重现这个问题。我们的查询很复杂,这就是为什么我们尝试切换到本机查询,而不是使用JQL(在没有此类问题的情况下)

谢谢

org.postgresql.util.PSQLException: ERROR: operator does not exist: boolean = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
    @Query(
        nativeQuery = true,
        value = "SELECT * FROM story WHERE is_internal = CAST(:isInternal AS boolean)",
        countQuery = "SELECT COUNT(*) FROM story WHERE is_internal = CAST(:isInternal AS boolean)"
    )
    fun findEmployeeStories(
        @Param("isInternal") isInternal: Boolean?,
        pageable: Pageable
    ): Page<StoryEntity>
org.postgresql.util.PSQLException: ERROR: cannot cast type bytea to boolean