Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.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
Java 错误:运算符不存在:spring jpa查询和postgres中的boolean=bytea_Java_Sql_Postgresql_Spring Data Jpa - Fatal编程技术网

Java 错误:运算符不存在:spring jpa查询和postgres中的boolean=bytea

Java 错误:运算符不存在:spring jpa查询和postgres中的boolean=bytea,java,sql,postgresql,spring-data-jpa,Java,Sql,Postgresql,Spring Data Jpa,当我在postgres中直接执行below查询时,它工作正常,但当我使用JPA运行时,就会出现below错误 查询示例: select * from products where clientId = :clientId and ((:status is null and status in (true, false)) or status = :status) and ((:anotherStatus is null an

当我在postgres中直接执行below查询时,它工作正常,但当我使用JPA运行时,就会出现below错误

查询示例:

select
    *
from
    products
where
    clientId = :clientId
    and ((:status is null
    and status in (true,
    false))
    or status = :status)
    and ((:anotherStatus is null
    and anotherStatus in (true,
    false))
    or anotherStatus = :anotherStatus);
@Query(value="select * from products where clientId = :clientId and ((:status is null and status in (true, false)) or status = :status) and ((:anotherStatus is null and anotherStatus in (true, false)) or anotherStatus = :anotherStatus)",nativeQuery=true)
List<Products> fetchProducts(@Param("clientId") Long clientId, @Param("status") Boolean status, @Param("anotherStatus") Boolean anotherStatus);
错误:

select
    *
from
    products
where
    clientId = :clientId
    and ((:status is null
    and status in (true,
    false))
    or status = :status)
    and ((:anotherStatus is null
    and anotherStatus in (true,
    false))
    or anotherStatus = :anotherStatus);
@Query(value="select * from products where clientId = :clientId and ((:status is null and status in (true, false)) or status = :status) and ((:anotherStatus is null and anotherStatus in (true, false)) or anotherStatus = :anotherStatus)",nativeQuery=true)
List<Products> fetchProducts(@Param("clientId") Long clientId, @Param("status") Boolean status, @Param("anotherStatus") Boolean anotherStatus);
错误org.hibernate.engine.jdbc.spi.SqlExceptionHelper-错误: 运算符不存在:boolean=bytea提示:没有匹配的运算符 给定的名称和参数类型。您可能需要添加显式类型 演员

在JPA中配置如下:

select
    *
from
    products
where
    clientId = :clientId
    and ((:status is null
    and status in (true,
    false))
    or status = :status)
    and ((:anotherStatus is null
    and anotherStatus in (true,
    false))
    or anotherStatus = :anotherStatus);
@Query(value="select * from products where clientId = :clientId and ((:status is null and status in (true, false)) or status = :status) and ((:anotherStatus is null and anotherStatus in (true, false)) or anotherStatus = :anotherStatus)",nativeQuery=true)
List<Products> fetchProducts(@Param("clientId") Long clientId, @Param("status") Boolean status, @Param("anotherStatus") Boolean anotherStatus);
@Query(value=“select*from products,其中clientId=:clientId和(:status为null,status为(true,false))或status=:status)和(:anotherStatus为null,anotherStatus为(true,false))或anotherStatus=:anotherStatus)”,nativeQuery=true)
列出fetchProducts(@Param(“clientId”)Long clientId、@Param(“status”)Boolean status、@Param(“anotherStatus”)Boolean anotherStatus);

基本上,我试图实现的是,当用户将param作为
true
发送时,使用
true
(活动)或作为
false
(活动)过滤产品,当用户不发送任何内容时(即
null
),然后获取所有产品(
true
false
)请记住,
null=null
true=null
false=null
都计算为
null
,在
where
-子句中被视为
false
。如果你还需要什么,请重新表述你的问题。 让我们看看
(:status为null,status为(true,false))或status=:status
的真值表

|-------------|-------------|-------------|
|   :status   |   status    |   result    |
|-------------|-------------|-------------|
|    null     |    null     |    false    |
|    null     |    true     |    true     |
|    null     |    false    |    true     |
|    true     |    null     |    false    |
|    true     |    true     |    true     |
|    true     |    false    |    false    |
|    false    |    null     |    false    |
|    false    |    true     |    false    |
|    false    |    false    |    true     |
|-------------|-------------|-------------|
换句话说,当
status
null
时,您需要一个始终返回
false
的子句。当
:status
null
时,这将使
为true
,如果
:status
status
具有相同的值,则为true

状态不为null且(:status为null或status=:status)

或者

状态不为空且合并(:状态,状态)=状态

请注意,对于您描述的错误,这仍然失败,因为在Java中传递
null
时,Hibernate将
:status
绑定为
BYTEA
。你可以通过双重施放来解决这个问题

CAST(CAST(:状态为字符变化)为布尔值)

如果这是您想要的,则生成的查询将是:

SELECT *
FROM products
WHERE status IS NOT NULL
AND anotherStatus IS NOT NULL
AND COALESCE(CAST(CAST(:status AS CHARACTER VARYING) AS BOOLEAN), status) = status
AND COALESCE(CAST(CAST(:anotherStatus AS CHARACTER VARYING) AS BOOLEAN), anotherStatus) = anotherStatus

:状态为空
:另一个状态为空
在我看来不受支持know@Eklavya-在JPA?中不受支持,那么我如何才能真正做到这一点…您能帮助我吗?可能在SQL中不受支持,请使用JPA规范进行搜索